package zj.com.net;

import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import android.widget.Toast;


import com.zfdang.multiple_images_selector.utilities.StringUtils;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.xutils.DbManager;
import org.xutils.common.Callback;
import org.xutils.http.RequestParams;
import org.xutils.x;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.UUID;

import cn.jpush.android.api.JPushInterface;
import zj.com.activities.DqrEditActivity;
import zj.com.activities.DqrListActivity;
import zj.com.app.ZjApplication;
import zj.com.db.DBUtil;
import zj.com.model.AppVersion;
import zj.com.model.AuditLog;
import zj.com.model.Dic;
import zj.com.model.DqrAccompany;
import zj.com.model.Dzg;
import zj.com.model.DzgDetail;
import zj.com.model.DzgDetailDB;
import zj.com.model.DzgInspectItemDB;
import zj.com.model.DzgInspectTask;
import zj.com.model.Gjgx;
import zj.com.model.GsTj;
import zj.com.model.GsTjOrg;
import zj.com.model.InspectContent;
import zj.com.model.InspectItem;
import zj.com.model.JcdInfoDB;
import zj.com.model.JcxDB;
import zj.com.model.JcxDetailDB;
import zj.com.model.Org;
import zj.com.model.Privilege;
import zj.com.model.PrjTj;
import zj.com.model.PrjTjDetail;
import zj.com.model.Project;
import zj.com.model.RecordDetail;
import zj.com.model.Stcj;
import zj.com.model.UploadFile;
import zj.com.model.User;
import zj.com.model.UserInfo;
import zj.com.model.Zy;
import zj.com.util.CommonUtil;
import zj.com.util.Constants;
import zj.com.util.LogUtils;
import zj.com.util.NetworkUtil;
import zj.com.util.SharedPreferencesUtil;
import zj.com.zj.R;

/**
 * Created by xi on 16/6/21.
 */
public class NetManager {

    public static final boolean DEBUG = true;
    private static Context mContext;
    private static NetManager mInstance;
    private Handler mHandler = new Handler(Looper.getMainLooper());

    NetManager(Context context) {
        mContext = context;
    }

    public static NetManager getInstance(Context context) {
        if (mInstance == null) {
            mInstance = new NetManager(context);
        }
        return mInstance;
    }


    /**
     * 检测条件是否允许提交请求
     *
     * @return
     */
    private boolean checkSubmitStatus(final OnAbstractListener lsn) {


        if (!NetworkUtil.isNetworkAvailable(mContext)) {

            lsn.onInternError(ErrorCode.NETWORK_UNAVAILABLE,
                    mContext.getString(R.string.network_unavailable));
            return false;
        }

        return true;

    };


    //登录
    public void doLogin(final String username,String pwd,final OnResponseListener<UserInfo> lsn){

        boolean isDebug = false;

        if (!checkSubmitStatus(lsn)) {
            return;
        }


        String  jpushRegisterID =  JPushInterface.getRegistrationID(mContext);

        LogUtils.getInstance().error("DeviceMAC===="+jpushRegisterID);


        RequestParams params = new RequestParams(Urls.LOGIN_URL);
        params.addBodyParameter("UserUid", username);
        params.addBodyParameter("Password", pwd);
        params.addBodyParameter("DeviceMAC", jpushRegisterID + "");


        x.http().post(params, new Callback.CommonCallback<String>() {

            @Override
            public void onSuccess(String result) {


                try {

                    LogUtils.getInstance().error(result);
                    JSONObject obj = new JSONObject(result);
                    boolean isSuccess = obj.getBoolean("Success");
                    String token = obj.getString("UserToken");
                    String UserUid = obj.getString("UserUid");

                    SharedPreferencesUtil.saveData(mContext, "token", token);
                    SharedPreferencesUtil.saveData(mContext, "uid", UserUid);
                    SharedPreferencesUtil.saveData(mContext, "username", username);

                    if (isSuccess) {
                        lsn.onComplete(true, null, ErrorCode.STATUS_OK, "登录成功");
                    } else {
                        lsn.onComplete(false, null, ErrorCode.STATUS_FAIL, "");

                    }


                } catch (Exception e) {

                    LogUtils.getInstance().error(e.toString());
                    lsn.onComplete(false, null, ErrorCode.STATUS_FAIL, "登录失败");
                }

                // lsn.onComplete(true,userInfo,ErrorCode.STATUS_OK,null);
            }

            @Override
            public void onError(Throwable throwable, boolean b) {

                LogUtils.getInstance().error(throwable.toString());
                lsn.onComplete(true, null, ErrorCode.STATUS_IO_EXCEPTION, throwable.toString());

            }

            @Override
            public void onCancelled(CancelledException e) {
                lsn.onComplete(false, null, ErrorCode.STATUS_FAIL, "登录失败");

            }

            @Override
            public void onFinished() {

            }
        });

    };


    //获取用户详细信息

    public void doGetUserInfo(final OnResponseListener<UserInfo> lsn){

        String token = (String) SharedPreferencesUtil.getData(mContext,"token", "");

        String uid = (String) SharedPreferencesUtil.getData(mContext,"uid", "");
        String url = String.format(Urls.USER_INFO, uid);

        RequestParams params = new RequestParams(url);

       // params.setHeader("UserToken",token);
        params.addHeader("UserToken",token);

        LogUtils.getInstance().error("url=" + url+"======token=="+token);

        x.http().get(params, new Callback.CommonCallback<String>() {


            @Override
            public void onSuccess(String s) {

                try {

                    LogUtils.getInstance().error("doGetUserInfo=" + s);
                    JSONObject obj = new JSONObject(s);

                    String UserUid = obj.getString("UserID");
                    String OrgCode = obj.getString("OrgCode");
                    String OrgFullName = obj.getString("OrgFullName");
                    String ProjectCode = obj.getString("ProjectCode");
                    String ProjectName = obj.getString("ProjectName");
                    String UserName = obj.getString("UserName");
                    //String RealName = obj.getString("RealName");
                    String UserLevel = obj.getString("UserLevel");
                    String UserSex = obj.getInt("UserSex") + "";
                    //String UserLocked = obj.getInt("UserLocked") + "";
                    String UserImageUrl = obj.getString("UserImageUrl");
                    String ProjectQRCodeUrl = obj.getString("ProjectQRCodeUrl");
                    String UserQRCodeUrl = obj.getString("UserQRCodeUrl");

                    boolean isSuccess = obj.getBoolean("Success");

                    if (isSuccess) {
                        UserInfo uinfo = new UserInfo();
                        uinfo.setUserUid(UserUid);
                        uinfo.setOrgCode(OrgCode);
                        uinfo.setOrgFullName(OrgFullName);
                        uinfo.setProjectCode(ProjectCode);
                        uinfo.setProjectName(ProjectName);
                        uinfo.setUserName(UserName);
                        // uinfo.setRealName(RealName);
                        uinfo.setUserLevel(UserLevel);
                        uinfo.setUserSex(UserSex);
                        //uinfo.setUserLocked(UserLocked);
                        uinfo.setUserImageUrl(UserImageUrl);
                        uinfo.setProjectQRCodeUrl(ProjectQRCodeUrl);
                        uinfo.setUserQRCodeUrl(UserQRCodeUrl);

                        SharedPreferencesUtil.saveObject(mContext, "user", uinfo);

                        lsn.onComplete(true, uinfo, ErrorCode.STATUS_OK, "成功");
                    } else {
                        lsn.onComplete(false, null, ErrorCode.STATUS_FAIL, "失败");

                    }


                } catch (Exception e) {
                    LogUtils.getInstance().error(e.toString());
                    lsn.onComplete(false, null, ErrorCode.STATUS_FAIL, "失败");
                }

            }

            @Override
            public void onError(Throwable throwable, boolean b) {
                LogUtils.getInstance().error(throwable.toString());

                lsn.onComplete(false, null, ErrorCode.STATUS_IO_EXCEPTION, throwable.toString());

            }

            @Override
            public void onCancelled(CancelledException e) {

            }

            @Override
            public void onFinished() {

            }
        });
    }


    //注销
    public void logout(final OnResponseListener<String> lsn){

        String token = (String) SharedPreferencesUtil.getData(mContext,"token","");
        String uid = (String) SharedPreferencesUtil.getData(mContext,"uid", "");

        String url = String.format(Urls.LOGOUT);
        RequestParams params = new RequestParams(Urls.LOGOUT);

        LogUtils.getInstance().error("token="+token);

        params.addBodyParameter("UserUid", uid);
        params.addBodyParameter("usertoken", token);
        params.addHeader("UserToken", token);

        x.http().post(params, new Callback.CommonCallback<String>() {


            @Override
            public void onSuccess(String s) {

                try {

                    LogUtils.getInstance().error(s);
                    JSONObject obj = new JSONObject(s);
                    boolean result = obj.getBoolean("Success");
                    if (result) {
                        lsn.onComplete(true, null, ErrorCode.STATUS_OK, "成功");

                    } else {
                        lsn.onComplete(false, null, ErrorCode.STATUS_FAIL, "失败");

                    }


                } catch (Exception e) {
                    LogUtils.getInstance().error(e.toString());

                    lsn.onComplete(false, null, ErrorCode.STATUS_FAIL, "失败");
                }

            }

            @Override
            public void onError(Throwable throwable, boolean b) {
                LogUtils.getInstance().error(throwable.toString());

                lsn.onComplete(false, null, ErrorCode.STATUS_IO_EXCEPTION, throwable.toString());

            }

            @Override
            public void onCancelled(CancelledException e) {

            }

            @Override
            public void onFinished() {

            }
        });
    }


    //专业列表

    public void obtainZy(final OnResponseListener<List<Zy>> lsn){

        String token = (String) SharedPreferencesUtil.getData(mContext,"token","");

        RequestParams params = new RequestParams(Urls.ZY);
        params.addHeader("UserToken", token);

        x.http().get(params, new Callback.CommonCallback<String>() {


            @Override
            public void onSuccess(String s) {

                try {

                    LogUtils.getInstance().error(s);
                    JSONObject obj = new JSONObject(s);
                    JSONArray array = obj.getJSONArray("SpecialtyList");
                    List<Zy> list = new ArrayList<Zy>();


                    for (int i = 0; i < array.length(); i++) {
                        Zy zy = new Zy();
                        JSONObject data = array.getJSONObject(i);
                        String SpecialtyName = data.getString("SpecialtyName");
                        String SpecialtyCode = data.getString("SpecialtyCode");

                        zy.setSpecialtyName(SpecialtyName);
                        zy.setSpecialtyCode(SpecialtyCode);
                        list.add(zy);

                    }

                    DBUtil.getInstance(mContext).getDBManager().save(list);
                    lsn.onComplete(true, list, ErrorCode.STATUS_OK, "成功");


                } catch (
                        Exception e
                        )

                {
                    lsn.onComplete(false, null, ErrorCode.STATUS_FAIL, "失败");
                }

            }

            @Override
            public void onError(Throwable throwable, boolean b) {
                lsn.onComplete(false, null, ErrorCode.STATUS_IO_EXCEPTION, throwable.toString());

            }

            @Override
            public void onCancelled(CancelledException e) {

            }

            @Override
            public void onFinished() {

            }
        });
    }

    //根据专业获取检查项信息

    public void obtainInspectItemList(final Zy zy,final OnResponseListener<List<InspectItem>> lsn){

        String token = (String) SharedPreferencesUtil.getData(mContext,"token","");

        String url = String.format(Urls.GetInspectItemList, zy.getSpecialtyCode());
        LogUtils.getInstance().error("专业获取检查项信息 url==="+url);

        RequestParams params = new RequestParams(url);
        params.addHeader("UserToken", token);

        x.http().get(params,new Callback.CommonCallback<String>() {


            @Override
            public void onSuccess(String s) {

                try {


                    LogUtils.getInstance().error("检查项信息：=="+s);
                    JSONObject obj = new JSONObject(s);
                    boolean isSuccess = obj.getBoolean("Success");
                    if (isSuccess) {
                        JSONArray array = obj.getJSONArray("InspectItemList");
                        List<InspectItem> inspects = new ArrayList<InspectItem>();
                        for (int i = 0; i < array.length(); i++) {

                            JSONObject data = array.getJSONObject(i);
                            int InspectItemID = data.getInt("InspectItemID");
                            String InspectItemName = data.getString("InspectItemName");
                            String InspectItemCode = data.getString("InspectItemCode");
                            int InspectType = data.getInt("InspectType");
                            //int RiskType = data.getInt("RiskType");
                            //String  RiskName = data.getString("RiskName");

                            //LogUtils.getInstance().error(RiskName);
                            InspectItem item = new InspectItem();
                            item.setInspectItemID(InspectItemID);
                            item.setInspectItemName(InspectItemName);
                            item.setInspectItemCode(InspectItemCode);
                            item.setSpecialtyCode(zy.getSpecialtyCode());
                            item.setZyName(zy.getSpecialtyName());
                            item.setInspectType(InspectType);
                            //item.setRiskType(RiskType);
                           // item.setRiskName(RiskName);

                            List<InspectContent> contentsList = new ArrayList<InspectContent>();
                            JSONArray contentArray = data.getJSONArray("InspectContentList");
                            for (int j = 0; j < contentArray.length(); j++) {

                                JSONObject contentObj = contentArray.getJSONObject(j);
                                int InspectContentID = contentObj.getInt("InspectContentID");
                                String InspectContentName = contentObj.getString("InspectContentName");
                                int MaxPoints = contentObj.getInt("MaxPoints");
                                int riskType = contentObj.getInt("RiskType");
                                String riskTypeName = contentObj.getString("RiskTypeName");

                                InspectContent content = new InspectContent();
                                content.setInspectItemID(InspectItemID);
                                content.setInspectContentID(InspectContentID + "");
                                content.setInspectContentName(InspectContentName);
                                content.setMaxPoints(MaxPoints);
                                content.setRiskType(riskType);
                                content.setRiskTypeName(riskTypeName);
                                contentsList.add(content);

                            }

                            DBUtil.getInstance(mContext).getDBManager().saveOrUpdate(contentsList);
                            item.setList(contentsList);
                            inspects.add(item);

                        }
                      DBUtil.getInstance(mContext).getDBManager().saveOrUpdate(inspects);
                        lsn.onComplete(true, inspects, ErrorCode.STATUS_OK, "成功");

                    }else{
                        lsn.onComplete(false, null, ErrorCode.STATUS_FAIL, "失败");

                    }
                }catch(Exception e){

                        LogUtils.getInstance().error(e.toString());
                        lsn.onComplete(false, null, ErrorCode.STATUS_FAIL, "失败");
                }


            }

            @Override
            public void onError(Throwable throwable, boolean b) {
                LogUtils.getInstance().error(throwable.toString());

                lsn.onComplete(false,null,ErrorCode.STATUS_IO_EXCEPTION,throwable.toString());

            }

            @Override
            public void onCancelled(CancelledException e) {

            }

            @Override
            public void onFinished() {

            }
        });
    }

    //获取字典信息
    public void obtainDic(final String type,final OnResponseListener<List<Dic>> lsn){

        String token = (String) SharedPreferencesUtil.getData(mContext,"token","");


        String url = String.format(Urls.dictionary, type);
        LogUtils.getInstance().error(url);
        RequestParams params = new RequestParams(url);
        params.addHeader("UserToken", token);
        x.http().get(params, new Callback.CommonCallback<String>() {


            @Override
            public void onSuccess(String s) {

                try {

                    LogUtils.getInstance().error(s);
                    JSONObject obj = new JSONObject(s);
                    boolean result = obj.getBoolean("Success");
                    if (result) {
                        List<Dic> list = new ArrayList<Dic>();
                        JSONArray array = obj.getJSONArray("DicList");
                        for (int i = 0; i < array.length(); i++) {
                            Dic dic = new Dic();
                            JSONObject data = array.getJSONObject(i);
                            String name = data.getString("Name");
                            String code = data.getString("Code");
                            String value = data.getString("Value");
                            UUID uuid = UUID.randomUUID();
                            dic.setId(uuid.toString());
                            dic.setName(name);
                            dic.setCode(code);
                            dic.setDicType(type);
                            dic.setValue(value);
                            list.add(dic);
                        }
                        DBUtil.getInstance(mContext).getDBManager().save(list);
                        lsn.onComplete(true, null, ErrorCode.STATUS_OK, "成功");
                    } else {
                        lsn.onComplete(false, null, ErrorCode.STATUS_FAIL, "失败");

                    }
                } catch (Exception e) {
                    LogUtils.getInstance().error(s);
                    lsn.onComplete(false, null, ErrorCode.STATUS_FAIL, "失败");
                }

            }

            @Override
            public void onError(Throwable throwable, boolean b) {
                lsn.onComplete(false, null, ErrorCode.STATUS_IO_EXCEPTION, throwable.toString());

            }

            @Override
            public void onCancelled(CancelledException e) {

            }

            @Override
            public void onFinished() {

            }
        });
    }


    //上传文件

    public void uploadFile(final JcxDetailDB jcdDetail,final OnResponseListener<List<UploadFile>> lsn){

        if(jcdDetail == null) return;
        String token = (String) SharedPreferencesUtil.getData(mContext,"token","");

        RequestParams params = new RequestParams(Urls.upload);

       String img =  jcdDetail.getImgs();
       String[] fileList =  img.split(",");
        if(fileList != null && fileList.length > 0){
            for (int i = 0; i < fileList.length; i++) {
                params.addBodyParameter("ResourcesList[" + i + "]", new File(fileList[i]));
            }
        }

        params.setMultipart(true);

        params.addHeader("UserToken", token);
        x.http().post(params, new Callback.CommonCallback<String>() {


            @Override
            public void onSuccess(String s) {
                LogUtils.getInstance().error(s);

                try {
                    JSONObject obj = new JSONObject(s);
                    boolean result = obj.getBoolean("Success");
                    if (result) {
                        JSONArray array = obj.getJSONArray("ResourcesList");
                        List<UploadFile> files = new ArrayList<UploadFile>();
                        StringBuffer sb = new StringBuffer();
                        DbManager dbManager = DBUtil.getInstance(mContext).getDBManager();
                        for (int i = 0; i < array.length(); i++) {
                            JSONObject data = array.getJSONObject(i);
                            String ResourceId = data.getString("ResourceId");
                            String Url = data.getString("Url");
                            UploadFile file = new UploadFile();
                            file.setResourceId(ResourceId);
                            file.setUrl(Url);
                            files.add(file);
                            sb.append(ResourceId);
                            sb.append(",");
                        }
                        jcdDetail.setUploadImgs(sb.toString());
                        dbManager.saveOrUpdate(jcdDetail);
                        lsn.onComplete(true, files, ErrorCode.STATUS_OK, "成功");

                    } else {
                        lsn.onComplete(false, null, ErrorCode.STATUS_FAIL, "失败");

                    }


                } catch (Exception e) {
                    LogUtils.getInstance().error(e.toString());
                    lsn.onComplete(false, null, ErrorCode.STATUS_FAIL, "失败");
                }

            }

            @Override
            public void onError(Throwable throwable, boolean b) {
                lsn.onComplete(false, null, ErrorCode.STATUS_IO_EXCEPTION, throwable.toString());

            }

            @Override
            public void onCancelled(CancelledException e) {

            }

            @Override
            public void onFinished() {

            }
        });
    }

    //提交检查单

    public void doAddInspection(final JcdInfoDB jcdInfo,final OnResponseListener<JcdInfoDB> lsn){

        String token = (String) SharedPreferencesUtil.getData(mContext,"token","");
        String uid = (String) SharedPreferencesUtil.getData(mContext,"uid","");

        RequestParams params = new RequestParams(Urls.addInspection);
        params.addHeader("UserToken", token);

        try {
            DbManager dbManager = DBUtil.getInstance(mContext).getDBManager();
            List<JcxDB> jcxList = dbManager.selector(JcxDB.class).where("InspectionNo", "=", jcdInfo.getInspectionNo()).findAll();

            JSONArray jsonArray = new JSONArray();
            for(JcxDB jcx:jcxList){


                List<JcxDetailDB> details = dbManager.selector(JcxDetailDB.class).where("inspectitemcode", "=", jcx.getInspectItemCode()).and("points",">","0").and("imgs", "!=", "").and("riskname", "!=", "").findAll();
                LogUtils.getInstance().error("=====update   details======" + details.size());

                if(details != null && details.size() > 0){
                    JSONArray jcxDetailArray = new JSONArray();
                    for(JcxDetailDB detail:details){
                        JSONObject detailObj = new JSONObject();
                        detailObj.put("RiskLevel",detail.getRiskLevel());
                        detailObj.put("RiskDesc",detail.getDesc());
                        detailObj.put("InspectContentID",detail.getContentId());
                        detailObj.put("Points",detail.getPoints());
                        JSONArray imgsArray = new JSONArray();

                        String upload = detail.getUploadImgs();
                        if(upload != null){
                            String[] uploads =  upload.split(",");
                            for(String u:uploads){
                                imgsArray.put(u);
                            }
                        }
                        detailObj.put("AttachIDList",imgsArray);
                        jcxDetailArray.put(detailObj);

                    }
                    JSONObject jcxObj = new JSONObject();
                    jcxObj.put("InspectItemCode", jcx.getInspectItemCode());
                    jcxObj.put("InspectTaskName", jcx.getTaskName());
                    jcxObj.put("RiskList", jcxDetailArray);
                    jcxObj.put("DeadLineDate",jcx.getEndDate());
                    jsonArray.put(jcxObj);
                }

            }

            String jdStr = jcdInfo.getJcr_id();
            JSONArray idArray = new JSONArray();
            if(jdStr != null){


                String[] ids =  jdStr.split(",");
                for(String u:ids){
                    idArray.put(u);
                }
            }

            JSONObject obj = new JSONObject();
            obj.put("UserID",uid);
            obj.put("InspectionNo",jcdInfo.getInspectionNo());
            obj.put("InspectType",jcdInfo.getInspectType());
            obj.put("InspectOrgCode",jcdInfo.getInspectOrgCode());
            obj.put("InspectProjectCode",jcdInfo.getInspectProjectCode());
            obj.put("InspectDate", jcdInfo.getInspectDate());
            obj.put("InspectionState", "0");
            obj.put("AccompanyPersonUIDs",idArray);
            obj.put("InspectionRemark", jcdInfo.getInspectionRemark());
            obj.put("InspectTaskList", jsonArray);
            params.setBodyContent(obj.toString());
            LogUtils.getInstance().error("========params=========" + obj.toString());


        }catch (Exception e){

        }

        LogUtils.getInstance().error(params.toString());

        x.http().post(params, new Callback.CommonCallback<String>() {


            @Override
            public void onSuccess(String s) {

                try {


                    LogUtils.getInstance().error(s);
                    JSONObject obj = new JSONObject(s);
                    boolean result = obj.getBoolean("Success");
                    if (result) {
                        lsn.onComplete(true, jcdInfo, ErrorCode.STATUS_OK, "成功");
                    } else {
                        lsn.onComplete(false, null, ErrorCode.STATUS_FAIL, "成功");

                    }


                } catch (Exception e) {
                    lsn.onComplete(false, null, ErrorCode.STATUS_FAIL, "失败");
                }

            }

            @Override
            public void onError(Throwable throwable, boolean b) {
                lsn.onComplete(false, null, ErrorCode.STATUS_IO_EXCEPTION, throwable.toString());

            }

            @Override
            public void onCancelled(CancelledException e) {

            }

            @Override
            public void onFinished() {

            }
        });
    }


    //待确认检查单列表
    public void obtainGetToBeConfirmedInspectionList(final OnResponseListener<List<JcdInfoDB>> lsn){

        String token = (String) SharedPreferencesUtil.getData(mContext,"token","");
        RequestParams params = new RequestParams(Urls.GetToBeConfirmedInspectionList);
        params.addHeader("UserToken", token);
        x.http().get(params, new Callback.CommonCallback<String>() {


            @Override
            public void onSuccess(String s) {

                try {

                    LogUtils.getInstance().error("待确认列表==========" + s);
                    List<JcdInfoDB> jcdList = new ArrayList<JcdInfoDB>();
                    JSONObject obj = new JSONObject(s);
                    JSONArray array = obj.getJSONArray("InspectionList");
                    DbManager dbManager = DBUtil.getInstance(mContext).getDBManager();
                    for (int i = 0; i < array.length(); i++) {

                        JSONObject data = array.getJSONObject(i);
                        int serverId = data.getInt("InspectionID");
                        String InspectionName = data.getString("InspectionName");
                        String InspectDate = data.getString("InspectDate");
                        InspectDate = InspectDate.replace("T", " ");
                        String InspectorName = data.getString("InspectorName");
                        int InspectType = data.getInt("InspectType");
                        String InspectOrgName = data.getString("InspectOrgName");
                        String InspectProjectName = data.getString("InspectProjectName");
                        //String AccompanyPersons = data.getString("AccompanyPersons");


                        Dic dic = dbManager.selector(Dic.class).where("dic_value", "=", InspectType + "").and("dic_type", "=", Constants.InspectType).findFirst();
                        JcdInfoDB info = new JcdInfoDB();

                        if (dic != null) {
                            info.setInspectTypeName(dic.getName());
                        }
                        info.setServerInpsectId(serverId);
                        info.setInspectionNo(InspectionName);
                        info.setInspectType(InspectType);
                        info.setInspectDate(InspectDate);
                        info.setProjectName(InspectProjectName);
                        info.setUnitName(InspectOrgName);
                        //info.setJcr(AccompanyPersons);
                        jcdList.add(info);
                    }
                    boolean result = obj.getBoolean("Success");
                    if (result) {
                        lsn.onComplete(true, jcdList, ErrorCode.STATUS_OK, "成功");

                    } else {
                        lsn.onComplete(false, null, ErrorCode.STATUS_FAIL, "失败");

                    }


                } catch (Exception e) {
                    LogUtils.getInstance().error(e.toString());

                }

            }

            @Override
            public void onError(Throwable throwable, boolean b) {
                lsn.onComplete(false, null, ErrorCode.STATUS_IO_EXCEPTION, throwable.toString());

            }

            @Override
            public void onCancelled(CancelledException e) {

            }

            @Override
            public void onFinished() {

            }
        });
    }

    //待确认检查项
    public void doGetInspectionDetail(String inspectNo,final OnResponseListener<JcdInfoDB> lsn){

        String token = (String) SharedPreferencesUtil.getData(mContext,"token","");

        String url = String.format(Urls.GetInspectionDetail, inspectNo);
        RequestParams params = new RequestParams(url);
        params.addHeader("UserToken", token);
        x.http().get(params, new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String s) {

                try {
                    LogUtils.getInstance().error("待确认检查下list=" + s);

                    DbManager dbManager = DBUtil.getInstance(mContext).getDBManager();

                    JcdInfoDB jcd = new JcdInfoDB();
                    JSONObject obj = new JSONObject(s);
                    boolean result = obj.getBoolean("Success");
                    int InspectionID = obj.getInt("InspectionID");
                    int InspectType = obj.getInt("InspectType");
                    String remark = obj.getString("InspectRemark");
                    String InspectOrgCode = obj.getString("InspectOrgCode");
                    String InspectDate = obj.getString("InspectDate");
                    String InspectOrgName = obj.getString("InspectOrgName");
                    String InspectProjectName = obj.getString("InspectProjectName");
                    String InspectionName = obj.getString("InspectionName");
                    String AccompanyPersons = obj.getString("AccompanyPersons");
                    String Inspector = obj.getString("Inspector");
                    jcd.setJcr(AccompanyPersons);
                    jcd.setInspectionRemark(remark);
                    jcd.setProjectName(InspectProjectName);
                    jcd.setUnitName(InspectOrgName);
                    jcd.setInspectDate(InspectDate);
                    jcd.setInspectType(InspectType);
                    jcd.setInspector(Inspector);
                    jcd.setServerInpsectId(InspectionID);
                    jcd.setInspectionNo(InspectionName);
                    Dic typeDic = dbManager.selector(Dic.class).where("dic_value", "=", InspectType + "").and("dic_type", "=", Constants.InspectType).findFirst();
                    if (typeDic != null) {
                        jcd.setInspectTypeName(typeDic.getName());
                    }
                    if (result) {

                        JSONArray array = obj.getJSONArray("InspectItemList");
                        List<JcxDB> jcxList = new ArrayList<JcxDB>();
                        for (int i = 0; i < array.length(); i++) {

                            JSONObject data = array.getJSONObject(i);
                            String InspectItemName = data.getString("InspectItemName");
                            int InspectContentID = data.getInt("InspectContentID");
                            String RiskName = data.getString("RiskName");
                            String RiskDesc = data.getString("RiskDesc");
                            int RiskLevel = data.getInt("RiskLevel");
                            int RiskPoints = data.getInt("RiskPoints");
                            int maxPoints = data.getInt("RiskTotalPoints");
                            String InspectContentName = data.getString("InspectContentName");

                            JSONArray attchArray = data.getJSONArray("RiskAttchUrlList");
                            StringBuffer sb = new StringBuffer();
                            for (int j = 0; j < attchArray.length(); j++) {
                                String url = attchArray.getString(j);
                                sb.append(url);
                                sb.append(",");
                            }
                            JcxDB jcx = new JcxDB();
                            Dic dic = dbManager.selector(Dic.class).where("dic_value", "=", RiskLevel + "").and("dic_type", "=", Constants.RiskLevel).findFirst();
                            if (dic != null) {
                                jcx.setRiskName(dic.getName());
                            }
                            jcx.setInspectItemName(InspectItemName);
                            jcx.setPoints(RiskPoints + "");
                            jcx.setRiskDes(RiskDesc);
                            jcx.setTotalPoints(maxPoints + "");
                            jcx.setImgs(sb.toString());
                            jcx.setInspectContentName(InspectContentName);
                            jcxList.add(jcx);
                        }

                        jcd.setJcxDBList(jcxList);
                        lsn.onComplete(true, jcd, ErrorCode.STATUS_OK, "成功");

                    } else {
                        lsn.onComplete(false, null, ErrorCode.STATUS_FAIL, "失败");

                    }


                } catch (Exception e) {
                    LogUtils.getInstance().error(e.toString());
                    lsn.onComplete(false, null, ErrorCode.STATUS_FAIL, "失败");
                }

            }

            @Override
            public void onError(Throwable throwable, boolean b) {
                LogUtils.getInstance().error(throwable.toString());

                lsn.onComplete(false, null, ErrorCode.STATUS_IO_EXCEPTION, throwable.toString());

            }

            @Override
            public void onCancelled(CancelledException e) {

            }

            @Override
            public void onFinished() {

            }
        });
    }

    //确认

    public void doConfirmInspection(String InspectionID, final OnResponseListener<List<JcxDB>> lsn){

        String token = (String) SharedPreferencesUtil.getData(mContext,"token","");
        String uid = (String) SharedPreferencesUtil.getData(mContext,"uid","");

        LogUtils.getInstance().error("InspectionID ===="+InspectionID);


        RequestParams params = new RequestParams(Urls.ConfirmInspection);
        params.addHeader("UserToken", token);
        params.addBodyParameter("UserID", uid);
        params.addBodyParameter("InspectionID", InspectionID);
        params.addBodyParameter("RepairPerson", ZjApplication.checkUser.getUserID());

        x.http().post(params, new Callback.CommonCallback<String>() {


            @Override
            public void onSuccess(String s) {

                try {
                    JSONObject obj = new JSONObject(s);
                    LogUtils.getInstance().error(s);
                    boolean success = obj.getBoolean("Success");
                    if (success) {
                        lsn.onComplete(true, null, ErrorCode.STATUS_OK, "失败");
                    } else {
                        lsn.onComplete(false, null, ErrorCode.STATUS_FAIL, "失败");
                    }

                } catch (Exception e) {
                    lsn.onComplete(false, null, ErrorCode.STATUS_FAIL, "失败");
                }

            }

            @Override
            public void onError(Throwable throwable, boolean b) {
                lsn.onComplete(false, null, ErrorCode.STATUS_IO_EXCEPTION, throwable.toString());

            }

            @Override
            public void onCancelled(CancelledException e) {

            }

            @Override
            public void onFinished() {

            }
        });
    }

    //待整改列表

    public void obtainGetToBeRepairedInspectionList(final OnResponseListener<List<Dzg>> lsn){

        String token = (String) SharedPreferencesUtil.getData(mContext,"token","");

        RequestParams params = new RequestParams(Urls.GetToBeRepairedInspectionList);
        params.addHeader("UserToken", token);
        x.http().get(params, new Callback.CommonCallback<String>() {


            @Override
            public void onSuccess(String s) {

                try {


                    LogUtils.getInstance().error("待整改" + s);
                    JSONObject obj = new JSONObject(s);
                    boolean result = obj.getBoolean("Success");

                    DbManager dbManager = DBUtil.getInstance(mContext).getDBManager();
                    if (result) {
                        JSONArray array = obj.getJSONArray("RepairRecordList");
                        List<Dzg> dzgList = new ArrayList<Dzg>();
                        for (int i = 0; i < array.length(); i++) {

                            JSONObject data = array.getJSONObject(i);
                            int RiskID = data.getInt("RiskID");
                            int InspectItemID = data.getInt("InspectItemID");
                            String InspectTaskName = data.getString("InspectTaskName");
                            int InspectionID = data.getInt("InspectionID");
                            String InspectOrgName = data.getString("InspectOrgName");
                            // int RiskType = data.getInt("RiskType");
                            int InspectType = data.getInt("InspectType");
                            String InspectDate = data.getString("InspectDate");
                            InspectDate = InspectDate.replace("T", " ");

                            String DeadLineDate = data.getString("DeadLineDate");
                            DeadLineDate = DeadLineDate.replace("T", " ");

                            Dzg dzg = new Dzg();

                            Dic dic = dbManager.selector(Dic.class).where("dic_value", "=", InspectType + "").and("dic_type", "=", Constants.InspectType).findFirst();
                            if (dic != null) {
                                dzg.setInspectTypeName(dic.getName());
                                LogUtils.getInstance().error("InspectType==" + InspectType + " name===" + dic.getName());
                            }
                            dzg.setRiskID(RiskID);
                            dzg.setInspectItemID(InspectItemID);
                            dzg.setInspectTaskName(InspectTaskName);
                            dzg.setInspectionID(InspectionID);
                            dzg.setInspectOrgName(InspectOrgName);
                            // dzg.setRiskType(RiskType);
                            dzg.setInspectType(InspectType);
                            dzg.setInspectDate(InspectDate);
                            dzg.setDeadLineDate(DeadLineDate);
                            dzgList.add(dzg);
                        }

                        lsn.onComplete(true, dzgList, ErrorCode.STATUS_OK, "");

                    } else {
                        lsn.onComplete(false, null, ErrorCode.STATUS_FAIL, "失败");

                    }


                    LogUtils.getInstance().error(s);


                } catch (Exception e) {
                    LogUtils.getInstance().error(e.toString());

                    lsn.onComplete(false, null, ErrorCode.STATUS_FAIL, "失败");
                }

            }

            @Override
            public void onError(Throwable throwable, boolean b) {
                lsn.onComplete(false, null, ErrorCode.STATUS_IO_EXCEPTION, throwable.toString());

            }

            @Override
            public void onCancelled(CancelledException e) {

            }

            @Override
            public void onFinished() {

            }
        });
    }


    //待审核列表

    public void obtainGetPenddingAuditRepairRecordList(final OnResponseListener<List<Dzg>> lsn){

        String token = (String) SharedPreferencesUtil.getData(mContext,"token","");

        RequestParams params = new RequestParams(Urls.GetPenddingAuditRepairRecordList);
        params.addHeader("UserToken", token);
        x.http().get(params, new Callback.CommonCallback<String>() {


            @Override
            public void onSuccess(String s) {

                try {

                    LogUtils.getInstance().error("待审核：" + s);
                    JSONObject obj = new JSONObject(s);
                    boolean result = obj.getBoolean("Success");

                    DbManager dbManager = DBUtil.getInstance(mContext).getDBManager();
                    if (result) {
                        List<Dzg> dzgList = new ArrayList<Dzg>();

                        if (!obj.isNull("PenddingAuditList")) {
                            JSONArray array = obj.getJSONArray("PenddingAuditList");
                            for (int i = 0; i < array.length(); i++) {

                                JSONObject data = array.getJSONObject(i);
                                int InspectItemID = data.getInt("InspectItemID");
                                String InspectTaskName = data.getString("InspectTaskName");
                                int InspectionID = data.getInt("InspectionID");
                                String InspectOrgName = data.getString("InspectOrgName");
                                int RiskType = data.getInt("RiskType");
                                int InspectType = data.getInt("InspectType");
                                String InspectDate = data.getString("InspectDate");
                                InspectDate = InspectDate.replace("T", " ");

                                String DeadLineDate = data.getString("DeadLineDate");
                                DeadLineDate = DeadLineDate.replace("T", " ");

                                // String InspectProfessionName = data.getString("InspectProfessionName");

                                Dzg dzg = new Dzg();

                                Dic dic = dbManager.selector(Dic.class).where("dic_value", "=", InspectType + "").and("dic_type", "=", Constants.InspectType).findFirst();
                                if (dic != null) {
                                    dzg.setInspectTypeName(dic.getName());
                                }
                                dzg.setInspectItemID(InspectItemID);
                                dzg.setInspectTaskName(InspectTaskName);
                                dzg.setInspectionID(InspectionID);
                                dzg.setInspectOrgName(InspectOrgName);
                                dzg.setRiskType(RiskType);
                                dzg.setInspectType(InspectType);
                                dzg.setInspectDate(InspectDate);
                                dzg.setDeadLineDate(DeadLineDate);
                                dzgList.add(dzg);
                            }

                        }

                        lsn.onComplete(true, dzgList, ErrorCode.STATUS_OK, "");


                    } else {
                        lsn.onComplete(false, null, ErrorCode.STATUS_FAIL, "失败");

                    }


                } catch (Exception e) {
                    LogUtils.getInstance().error(e.toString());

                    lsn.onComplete(false, null, ErrorCode.STATUS_FAIL, "失败");
                }

            }

            @Override
            public void onError(Throwable throwable, boolean b) {
                lsn.onComplete(false, null, ErrorCode.STATUS_IO_EXCEPTION, throwable.toString());

            }

            @Override
            public void onCancelled(CancelledException e) {

            }

            @Override
            public void onFinished() {

            }
        });
    }

    //获取待整改明细

    public void GetToBeRepairedInspectionDetail(String InspectionID,String InspectionItemID, final OnResponseListener<DzgDetail> lsn){

        String token = (String) SharedPreferencesUtil.getData(mContext,"token","");

        String url = String.format(Urls.GetToBeRepairedInspectionDetail, InspectionID,InspectionItemID);
        LogUtils.getInstance().error("url===" + url);
        RequestParams params = new RequestParams(url);
        params.addHeader("UserToken", token);
        x.http().get(params, new Callback.CommonCallback<String>() {


            @Override
            public void onSuccess(String s) {

                try {

                    LogUtils.getInstance().error("待整改详情=====" + s);

                    JSONObject obj = new JSONObject(s);
                    boolean success = obj.getBoolean("Success");
                    if (success) {
                        DzgDetail detail = new DzgDetail();
                        // int RiskID = obj.getInt("RiskID");
                        int InspectionID = obj.getInt("InspectionID");
                        int InspectItemID = obj.getInt("InspectItemID");
                        String InspectProfessionName = obj.getString("InspectProfessionName");
                        String InspectItemName = obj.getString("InspectItemName");
                        String InspectTaskName = obj.getString("InspectTaskName");
                        String InspectType = obj.getString("InspectType");
                        // int RiskType = obj.getInt("RiskType");
                        String InspectOrgCode = obj.getString("InspectOrgCode");
                        String InspectOrgName = obj.getString("InspectOrgName");
                        int InspectCompanyID = obj.getInt("InspectCompanyID");
                        String InspectProjectDPTID = obj.getString("InspectProjectDPTID");
                        int InspectProjectID = obj.getInt("InspectProjectID");
                        String InspectProjectDPTName = obj.getString("InspectProjectDPTName");
                        String InspectProjectName = obj.getString("InspectProjectName");
                        String DeadLine = obj.getString("DeadLine");
                        // detail.setRiskID(RiskID);
                        detail.setInspectionID(InspectionID);
                        detail.setInspectItemID(InspectItemID);
                        detail.setInspectProfessionName(InspectProfessionName);
                        detail.setInspectItemName(InspectItemName);
                        detail.setInspectTaskName(InspectTaskName);
                        detail.setInspectType(InspectType);
                        //detail.setRiskType(RiskType);
                        detail.setInspectOrgCode(InspectOrgCode);
                        detail.setInspectOrgName(InspectOrgName);
                        detail.setInspectCompanyID(InspectCompanyID);
                        detail.setInspectProjectDPTID(InspectProjectDPTID);
                        detail.setInspectProjectID(InspectProjectID);
                        detail.setInspectProjectDPTName(InspectProjectDPTName);
                        detail.setInspectProjectName(InspectProjectName);
                        detail.setDeadLine(DeadLine);

                        JSONArray array = obj.getJSONArray("InspectTaskList");
                        List<DzgInspectTask> dzgs = new ArrayList<DzgInspectTask>();
                        for (int i = 0; i < array.length(); i++) {

                            DzgInspectTask task = new DzgInspectTask();
                            JSONObject data = array.getJSONObject(i);
                            int InspectTaskID = data.getInt("InspectTaskID");
                            int Points = data.getInt("Points");
                            String InspectContentDesc = data.getString("InspectContentDesc");
                            String InspectRiskDesc = data.getString("InspectRiskDesc");
                            String InspectContentStatus = data.getString("InspectContentStatus");
                            String InspectContentAuditStatus = data.getString("InspectContentAuditStatus");
                            int riskType = data.getInt("RiskType");
                            String RiskTypeName = data.getString("RiskTypeName");
                            task.setInspectTaskID(InspectTaskID);
                            task.setPoints(Points);
                            task.setInspectContentDesc(InspectContentDesc);
                            task.setInspectRiskDesc(InspectRiskDesc);
                            task.setInspectContentStatus(InspectContentStatus);
                            task.setInspectContentAuditStatus(InspectContentAuditStatus);
                            task.setRiskType(riskType);
                            task.setRiskTypeName(RiskTypeName);
                            JSONArray imgArray = data.getJSONArray("RiskAttshUrlList");
                            List<String> imgs = new ArrayList<String>();
                            for (int j = 0; j < imgArray.length(); j++) {
                                String img = imgArray.getString(j);
                                imgs.add(img);
                            }
                            task.setImgList(imgs);
                            dzgs.add(task);
                        }

                        detail.setTaskList(dzgs);
                        lsn.onComplete(true, detail, ErrorCode.STATUS_OK, "失败");

                    } else {
                        lsn.onComplete(false, null, ErrorCode.STATUS_FAIL, "失败");

                    }


                } catch (Exception e) {
                    LogUtils.getInstance().error(e.toString());
                    lsn.onComplete(false, null, ErrorCode.STATUS_FAIL, "失败");
                }

            }

            @Override
            public void onError(Throwable throwable, boolean b) {
                LogUtils.getInstance().error(throwable.toString());

                lsn.onComplete(false, null, ErrorCode.STATUS_IO_EXCEPTION, throwable.toString());

            }

            @Override
            public void onCancelled(CancelledException e) {

            }

            @Override
            public void onFinished() {

            }
        });
    }


    //整改明细审核列表
    public void GetRiskRepairRecordDetail(String InspectionID,String RepairID,final OnResponseListener<RecordDetail> lsn){

        String token = (String) SharedPreferencesUtil.getData(mContext,"token","");

        String url = String.format(Urls.GetRiskRepairRecordDetail,InspectionID, RepairID);
        LogUtils.getInstance().error("审核明细===" + url);
        RequestParams params = new RequestParams(url);
        params.addHeader("UserToken", token);
        x.http().get(params, new Callback.CommonCallback<String>() {


            @Override
            public void onSuccess(String s) {

                try {


                    JSONObject obj = new JSONObject(s);
                    boolean Success = obj.getBoolean("Success");
                    if (Success) {

                        RecordDetail record = new RecordDetail();
                        JSONArray array = obj.getJSONArray("AuditLogList");
                        String RiskDesc = obj.getString("RiskDesc");
                        String RepairDesc = obj.getString("RepairDesc");
                        String RepairUserName = obj.getString("RepairUserName");
                        String RepairDate = obj.getString("RiskDesc");
                        record.setRiskDesc(RiskDesc);
                        record.setRepairDesc(RepairDesc);
                        record.setRepairUserName(RepairUserName);
                        record.setRepairDate(RepairDate);
                        List<String> riskList = new ArrayList<String>();
                        List<String> attachList = new ArrayList<String>();

                        JSONArray RiskAttachUrlList = obj.getJSONArray("RiskAttachUrlList");
                        JSONArray AttachUrlList = obj.getJSONArray("RepairAttachUrlList");
                        for (int j = 0; j < RiskAttachUrlList.length(); j++) {


                            riskList.add(RiskAttachUrlList.getString(j));
                        }
                        for (int n = 0; n < AttachUrlList.length(); n++) {


                            attachList.add(AttachUrlList.getString(n));
                        }
                        record.setAttachUrlList(attachList);
                        record.setRiskAttachUrlList(riskList);
                        List<AuditLog> list = new ArrayList<AuditLog>();
                        for (int i = 0; i < array.length(); i++) {

                            JSONObject data = array.getJSONObject(i);
                            String AuditUser = data.getString("AuditUser");
                            int AuditID = data.getInt("AuditID");
                            String AuditDate = data.getString("AuditDate");
                            String AuditDesc = data.getString("AuditDesc");
                            String AuditResult = data.getString("AuditResult");

                            AuditLog log = new AuditLog();
                            log.setAuditDate(AuditDate);
                            log.setAuditDesc(AuditDesc);
                            log.setAuditResult(AuditResult);
                            list.add(log);
                        }
                        record.setAuditLog(list);
                        lsn.onComplete(true, record, ErrorCode.STATUS_FAIL, "失败");

                    } else {
                        lsn.onComplete(false, null, ErrorCode.STATUS_FAIL, "失败");

                    }
                    LogUtils.getInstance().error("待整改审批：" + s);


                } catch (Exception e) {
                    LogUtils.getInstance().error("GetRiskRepairRecordDetail=" + e.toString());
                    lsn.onComplete(false, null, ErrorCode.STATUS_FAIL, "失败");
                }

            }

            @Override
            public void onError(Throwable throwable, boolean b) {
                lsn.onComplete(false, null, ErrorCode.STATUS_IO_EXCEPTION, throwable.toString());

            }

            @Override
            public void onCancelled(CancelledException e) {

            }

            @Override
            public void onFinished() {

            }
        });
    }

    //提交待整改的
    public void AddRepairRecord(final Dzg dzg,final OnResponseListener<Dzg> lsn){

        DbManager dbManager = DBUtil.getInstance(mContext).getDBManager();
        String token = (String) SharedPreferencesUtil.getData(mContext,"token","");
        String uid = (String) SharedPreferencesUtil.getData(mContext,"uid","");
        JSONObject obj = new JSONObject();
        try{
            DzgDetailDB detail =  dbManager.selector(DzgDetailDB.class).where("inspection_id", "=",dzg.getInspectionID()).where("inspectionitem_id", "=", dzg.getInspectItemID()).findFirst();
            obj.put("UserID", uid);

            if(detail != null){
                obj.put("RiskID",dzg.getRiskID());
                obj.put("InspectionID",dzg.getInspectionID());
                obj.put("InspectionItemID",dzg.getInspectItemID());

                List<DzgInspectItemDB> tasks =  dbManager.selector(DzgInspectItemDB.class).where("inspectionitem_id", "=",dzg.getInspectItemID()).findAll();
                JSONArray array = new JSONArray();
                if(tasks != null){
                    for(int i=0;i<tasks.size();i++){
                        DzgInspectItemDB item =   tasks.get(i);
                        JSONObject itemObj = new JSONObject();
                        itemObj.put("InspectTaskID",item.getInspectContentID());
                        itemObj.put("RepairDesc",item.getRepairDesc());
                        String img =  item.getUploadImgs();
                        JSONArray imgArray = new JSONArray();
                        if(img != null){
                          String[] imgs =   img.split(",");
                            for(String url:imgs){
                                imgArray.put(url);
                            }
                        }
                        itemObj.put("AttachList",imgArray);
                        array.put(itemObj);
                    }

                }

                obj.put("RepairRecordList",array);
            }

        }catch(Exception e){

        }



        LogUtils.getInstance().error("提交待整改参数:" + obj.toString());
        RequestParams params = new RequestParams(Urls.AddRepairRecord);
        params.setBodyContent(obj.toString());
        params.addHeader("UserToken", token);
        x.http().post(params, new Callback.CommonCallback<String>() {


            @Override
            public void onSuccess(String s) {

                try {

                    LogUtils.getInstance().error("提交待整改的：" + s);
                    JSONObject obj = new JSONObject(s);
                    boolean Success = obj.getBoolean("Success");
                    if (Success) {
                        lsn.onComplete(true, dzg, ErrorCode.STATUS_FAIL, "失败");

                    } else {
                        lsn.onComplete(false, null, ErrorCode.STATUS_FAIL, "失败");

                    }

                } catch (Exception e) {
                    lsn.onComplete(false, null, ErrorCode.STATUS_FAIL, "失败");
                }

            }

            @Override
            public void onError(Throwable throwable, boolean b) {
                lsn.onComplete(false, null, ErrorCode.STATUS_IO_EXCEPTION, throwable.toString());

            }

            @Override
            public void onCancelled(CancelledException e) {

            }

            @Override
            public void onFinished() {

            }
        });
    }


    public void newUploadImg(final String imgs,final OnResponseListener<List<UploadFile>> lsn){

        if(imgs == null){

            LogUtils.getInstance().error("====imgs====="+imgs);
            return;
        }


        String token = (String) SharedPreferencesUtil.getData(mContext,"token","");

        RequestParams params = new RequestParams(Urls.upload);

        String[] fileList =  imgs.split(",");
        if(fileList != null && fileList.length > 0){
            for (int i = 0; i < fileList.length; i++) {
                LogUtils.getInstance().error("=====file==="+fileList[i]);
                params.addBodyParameter("ResourcesList[" + i + "]", new File(fileList[i]));
            }
        }

        params.setMultipart(true);
        params.addHeader("UserToken", token);
        x.http().post(params, new Callback.CommonCallback<String>() {


            @Override
            public void onSuccess(String s) {
                LogUtils.getInstance().error(s);

                try {
                    JSONObject obj = new JSONObject(s);
                    boolean result = obj.getBoolean("Success");
                    if (result) {
                        JSONArray array = obj.getJSONArray("ResourcesList");
                        List<UploadFile> files = new ArrayList<UploadFile>();
                        StringBuffer sb = new StringBuffer();
                        DbManager dbManager = DBUtil.getInstance(mContext).getDBManager();
                        for (int i = 0; i < array.length(); i++) {
                            JSONObject data = array.getJSONObject(i);
                            String ResourceId = data.getString("ResourceId");
                            String Url = data.getString("Url");
                            UploadFile file = new UploadFile();
                            file.setResourceId(ResourceId);
                            file.setUrl(Url);
                            files.add(file);
                            sb.append(ResourceId);
                            sb.append(",");
                        }
                        lsn.onComplete(true, files, ErrorCode.STATUS_OK, "成功");

                    } else {
                        lsn.onComplete(false, null, ErrorCode.STATUS_FAIL, "失败");

                    }


                } catch (Exception e) {
                    LogUtils.getInstance().error(e.toString());
                    lsn.onComplete(false, null, ErrorCode.STATUS_FAIL, "失败");
                }

            }

            @Override
            public void onError(Throwable throwable, boolean b) {
                LogUtils.getInstance().error("=========" + throwable.toString());
                lsn.onComplete(false, null, ErrorCode.STATUS_IO_EXCEPTION, throwable.toString());

            }

            @Override
            public void onCancelled(CancelledException e) {

            }

            @Override
            public void onFinished() {

            }
        });
    }

    //待整改 审核 拒绝操作

    public void AuditRepairRecord(String request ,final OnResponseListener<List<JcxDB>> lsn){

        String token = (String) SharedPreferencesUtil.getData(mContext,"token","");

        RequestParams params = new RequestParams(Urls.AuditRepairRecord);
        params.setBodyContent(request);
        params.addHeader("UserToken", token);
        x.http().post(params, new Callback.CommonCallback<String>() {


            @Override
            public void onSuccess(String s) {

                try {

                    JSONObject obj = new JSONObject(s);
                    boolean Success = obj.getBoolean("Success");
                    if (Success) {
                        lsn.onComplete(true, null, ErrorCode.STATUS_OK, "失败");

                    } else {
                        lsn.onComplete(false, null, ErrorCode.STATUS_FAIL, "失败");

                    }

                } catch (Exception e) {
                    lsn.onComplete(false, null, ErrorCode.STATUS_FAIL, "失败");
                }

            }

            @Override
            public void onError(Throwable throwable, boolean b) {
                lsn.onComplete(false, null, ErrorCode.STATUS_IO_EXCEPTION, throwable.toString());

            }

            @Override
            public void onCancelled(CancelledException e) {

            }

            @Override
            public void onFinished() {

            }
        });
    }


    //获取公司
    public void QueryOrgs(final OnResponseListener<List<Org>> lsn){

        final String token = (String) SharedPreferencesUtil.getData(mContext,"token","");
        String uid = (String) SharedPreferencesUtil.getData(mContext,"uid","");

        String url = String.format(Urls.QueryOrgs, uid);
        RequestParams params = new RequestParams(url);
        params.addHeader("UserToken", token);
        LogUtils.getInstance().error(token+"获取公司===" + url);

        x.http().get(params, new Callback.CommonCallback<String>() {


            @Override
            public void onSuccess(String s) {

                try {
                    LogUtils.getInstance().error("获取公司===" + s);
                    JSONObject obj = new JSONObject(s);
                    boolean success = obj.getBoolean("Success");
                    List<Org> orgs = new ArrayList<Org>();
                    List<Org> list = new ArrayList<Org>();
                    if (success) {

                        JSONArray array = obj.getJSONArray("OrgList");
                        for (int i = 0; i < array.length(); i++) {

                            JSONObject data = array.getJSONObject(i);
                            String OrgName = data.getString("OrgName");
                            String OrgCode = data.getString("OrgCode");
                            String OrgType = data.getString("OrgType");
                            String ParentOrgCode = data.getString("ParentOrgCode");
                            String ParentOrgName = data.getString("ParentOrgName");
                            String UnitCode = data.getString("UnitCode");
                            String UnitName = data.getString("UnitName");
                            String OrgGlobalNo = data.getString("OrgGlobalNo");
                            int OrgLevel = data.getInt("OrgLevel");
                            int OrgSequence = data.getInt("OrgSequence");

                            Org org = new Org();
                            org.setOrgName(OrgName);
                            org.setOrgCode(OrgCode);
                            org.setOrgType(OrgType);
                            org.setParentOrgCode(ParentOrgCode);
                            org.setParentOrgName(ParentOrgName);
                            org.setUnitCode(UnitCode);
                            org.setUnitName(UnitName);
                            org.setOrgGlobalNo(OrgGlobalNo);
                            org.setOrgLevel(OrgLevel);
                            org.setOrgSequence(OrgSequence);


                            orgs.add(org);

                            if (OrgLevel == 0) {
                                list.add(org);
                            }


                        }

                        lsn.onComplete(true, list, ErrorCode.STATUS_OK, "失败");

                    } else {
                        lsn.onComplete(false, null, ErrorCode.STATUS_FAIL, "失败");

                    }


                } catch (Exception e) {
                    LogUtils.getInstance().error(e.toString());
                    lsn.onComplete(false, null, ErrorCode.STATUS_FAIL, "失败");
                }

            }

            @Override
            public void onError(Throwable throwable, boolean b) {
                LogUtils.getInstance().error(throwable.toString());
                lsn.onComplete(false, null, ErrorCode.STATUS_IO_EXCEPTION, throwable.toString());

            }

            @Override
            public void onCancelled(CancelledException e) {

            }

            @Override
            public void onFinished() {

            }
        });
    }

    //检查人选择
    public void GetUserListByKeyWord(String keyword ,String userRole,String depNo,final OnResponseListener<List<User>> lsn){

        String token = (String) SharedPreferencesUtil.getData(mContext,"token","");
        String url = String.format(Urls.GetUserListByKeyWord, keyword,userRole,depNo);
        LogUtils.getInstance().error("search===" + url);
        RequestParams params = new RequestParams(url);
        params.addHeader("UserToken", token);

        x.http().get(params, new Callback.CommonCallback<String>() {


            @Override
            public void onSuccess(String s) {

                try {

                    LogUtils.getInstance().error(s);
                    JSONObject obj = new JSONObject(s);
                    boolean Success = obj.getBoolean("Success");
                    if (Success) {
                        List<User> list = new ArrayList<User>();

                        if (!obj.isNull("UserList")) {
                            JSONArray array = obj.getJSONArray("UserList");
                            for (int i = 0; i < array.length(); i++) {
                                JSONObject data = array.getJSONObject(i);
                                String UserID = data.getString("UserID");
                                String UserName = data.getString("UserName");
                                User user = new User();
                                user.setUserID(UserID);
                                user.setUserName(UserName);
                                list.add(user);
                            }

                        }

                        lsn.onComplete(true, list, ErrorCode.STATUS_FAIL, "失败");

                    } else {
                        lsn.onComplete(false, null, ErrorCode.STATUS_FAIL, "失败");

                    }

                } catch (Exception e) {
                    lsn.onComplete(false, null, ErrorCode.STATUS_FAIL, "失败");
                }

            }

            @Override
            public void onError(Throwable throwable, boolean b) {
                lsn.onComplete(false, null, ErrorCode.STATUS_IO_EXCEPTION, throwable.toString());

            }

            @Override
            public void onCancelled(CancelledException e) {

            }

            @Override
            public void onFinished() {

            }
        });
    }

    //部门选择
    public void queryBm(String orgCode,final OnResponseListener<List<Org>> lsn){

        String token = (String) SharedPreferencesUtil.getData(mContext,"token","");

        String url = String.format(Urls.GetChildren, orgCode);
        RequestParams params = new RequestParams(url);
        params.addHeader("UserToken", token);
        x.http().get(params, new Callback.CommonCallback<String>() {


            @Override
            public void onSuccess(String s) {

                try {
                    JSONObject obj = new JSONObject(s);
                    boolean success = obj.getBoolean("Success");
                    List<Org> orgs = new ArrayList<Org>();
                    List<Org> list = new ArrayList<Org>();
                    if (success) {

                        JSONArray array = obj.getJSONArray("OrgList");
                        for (int i = 0; i < array.length(); i++) {

                            JSONObject data = array.getJSONObject(i);
                            String OrgName = data.getString("OrgName");
                            String OrgCode = data.getString("OrgCode");
                            String OrgType = data.getString("OrgType");
                            String ParentOrgCode = data.getString("ParentOrgCode");
                            String ParentOrgName = data.getString("ParentOrgName");
                            String UnitCode = data.getString("UnitCode");
                            String UnitName = data.getString("UnitName");
                            String OrgGlobalNo = data.getString("OrgGlobalNo");
                            int OrgLevel = data.getInt("OrgLevel");
                            int OrgSequence = data.getInt("OrgSequence");

                            Org org = new Org();
                            org.setOrgName(OrgName);
                            org.setOrgCode(OrgCode);
                            org.setOrgType(OrgType);
                            org.setParentOrgCode(ParentOrgCode);
                            org.setParentOrgName(ParentOrgName);
                            org.setUnitCode(UnitCode);
                            org.setUnitName(UnitName);
                            org.setOrgGlobalNo(OrgGlobalNo);
                            org.setOrgLevel(OrgLevel);
                            org.setOrgSequence(OrgSequence);


                            list.add(org);


                        }

                        lsn.onComplete(true, list, ErrorCode.STATUS_OK, "失败");

                    } else {
                        lsn.onComplete(false, null, ErrorCode.STATUS_FAIL, "失败");

                    }


                } catch (Exception e) {
                    LogUtils.getInstance().error(e.toString());
                    lsn.onComplete(false, null, ErrorCode.STATUS_FAIL, "失败");
                }


            }

            @Override
            public void onError(Throwable throwable, boolean b) {
                lsn.onComplete(false, null, ErrorCode.STATUS_IO_EXCEPTION, throwable.toString());

            }

            @Override
            public void onCancelled(CancelledException e) {

            }

            @Override
            public void onFinished() {

            }
        });
    }

    //隐患类别统计

    public void GetAnalysisForCompanyByInspectype(final  int type,String request,final OnResponseListener<List<GsTj>> lsn){

        String token = (String) SharedPreferencesUtil.getData(mContext,"token","");

        RequestParams params = new RequestParams(Urls.GetAnalysisForCompanyByRiskType);
        LogUtils.getInstance().error("公司统计=="+Urls.GetAnalysisForCompanyByRiskType);
        params.addHeader("UserToken", token);
        params.setBodyContent(request);
        x.http().post(params, new Callback.CommonCallback<String>() {


            @Override
            public void onSuccess(String s) {

                try {


                    DbManager dbManager = DBUtil.getInstance(mContext).getDBManager();

                    LogUtils.getInstance().error(s);

                    JSONObject obj = new JSONObject(s);
                    JSONArray array = obj.getJSONArray("DataList");
                    List<GsTj> gsList = new ArrayList<GsTj>();
                    for (int i = 0; i < array.length(); i++) {

                        GsTj gstj = new GsTj();
                        JSONObject data = array.getJSONObject(i);
                        int RiskType = -1;
                        int InspectType = -1;
                        int RiskLevel = -1;
                        String name = "";
                        if (type == 0) {
                            RiskType = data.getInt("RiskType");
                            Dic riskDic = dbManager.selector(Dic.class).where("dic_value", "=", RiskType + "").and("dic_type", "=", Constants.RiskType).findFirst();
                            if (riskDic != null) {
                                String riskTypeName = riskDic.getName();
                                gstj.setRiskTypeName(riskTypeName);
                                name = riskTypeName;
                                LogUtils.getInstance().error(riskTypeName);
                            }
                            gstj.setRiskType(RiskType);
                        } else if (type == 1) {

                            InspectType = data.getInt("InspectType");
                            Dic InspectTypeDic = dbManager.selector(Dic.class).where("dic_value", "=", InspectType + "").and("dic_type", "=", Constants.InspectType).findFirst();
                            if (InspectTypeDic != null) {
                                name = InspectTypeDic.getName();
                                gstj.setInspectTypeName(InspectTypeDic.getName());
                            }
                            gstj.setInspectType(InspectType);

                        } else if (type == 2) {
                            RiskLevel = data.getInt("RiskLevel");
                            Dic RiskLevelDic = dbManager.selector(Dic.class).where("dic_value", "=", RiskLevel + "").and("dic_type", "=", Constants.RiskLevel).findFirst();
                            if (RiskLevelDic != null) {
                                name = RiskLevelDic.getName();
                                gstj.setRiskLevelName(RiskLevelDic.getName());
                            }
                            gstj.setRiskLevel(RiskLevel);
                        } else if (type == 3) {
                            name = data.getString("ItemName");
                            gstj.setItemName(data.getString("ItemName"));
                        }
                        gstj.setName(name);


                        JSONArray orgArray = data.getJSONArray("OrgList");
                        List<GsTjOrg> orgs = new ArrayList<GsTjOrg>();
                        int totalCount = 0;
                        for (int j = 0; j < orgArray.length(); j++) {

                            JSONObject orgObj = orgArray.getJSONObject(j);
                            String OrgName = orgObj.getString("OrgName");
                            int AnalysisCount = orgObj.getInt("AnalysisCount");
//                            if(AnalysisCount == 0){
//                                AnalysisCount = new Random().nextInt(100);
//                            }
                            totalCount += AnalysisCount;
                            String OrgCode = orgObj.getString("OrgCode");
                            GsTjOrg org = new GsTjOrg();
                            org.setOrgName(OrgName);
                            org.setAnalysisCount(AnalysisCount);
                            org.setOrgCode(OrgCode);
                            orgs.add(org);

                        }
                        gstj.setTotalCount(totalCount);
                        gstj.setOrgsList(orgs);
                        gsList.add(gstj);
                    }


                    lsn.onComplete(true, gsList, ErrorCode.STATUS_OK, "失败");

                } catch (Exception e) {
                    LogUtils.getInstance().error(e.toString());
                    lsn.onComplete(false, null, ErrorCode.STATUS_FAIL, "失败");
                }

            }

            @Override
            public void onError(Throwable throwable, boolean b) {
                LogUtils.getInstance().error(throwable.toString());
                lsn.onComplete(false, null, ErrorCode.STATUS_IO_EXCEPTION, throwable.toString());

            }

            @Override
            public void onCancelled(CancelledException e) {

            }

            @Override
            public void onFinished() {

            }
        });
    }

    //获取项目列表
    public void GetProjectList(String code,final OnResponseListener<List<Project>> lsn){

        String token = (String) SharedPreferencesUtil.getData(mContext,"token","");

        String url = String.format(Urls.GetProjectList, code);
        RequestParams params = new RequestParams(url);
        params.addHeader("UserToken", token);
        LogUtils.getInstance().error("项目========url======" + url);

        x.http().get(params, new Callback.CommonCallback<String>() {


            @Override
            public void onSuccess(String s) {

                try {
                    LogUtils.getInstance().error("项目==============" + s);
                    JSONObject obj = new JSONObject(s);
                    boolean Success = obj.getBoolean("Success");
                    List<Project> list = new ArrayList<Project>();
                    if (Success) {

                        if (!obj.isNull("ProjectList")) {
                            JSONArray array = obj.getJSONArray("ProjectList");
                            for (int i = 0; i < array.length(); i++) {
                                JSONObject data = array.getJSONObject(i);
                                int ProjectID = data.getInt("ProjectID");
                                String ProjectName = data.getString("ProjectName");
                                String ProjectCode = data.getString("ProjectCode");
                                Project prj = new Project();
                                prj.setProjectID(ProjectID);
                                prj.setProjectCode(ProjectCode);
                                prj.setProjectName(ProjectName);
                                list.add(prj);
                            }
                        }
                        lsn.onComplete(true, list, ErrorCode.STATUS_OK, "失败");

                    } else {
                        lsn.onComplete(false, null, ErrorCode.STATUS_OK, "失败");

                    }
                } catch (Exception e) {
                    LogUtils.getInstance().error(e.toString());
                    lsn.onComplete(false, null, ErrorCode.STATUS_FAIL, "失败");
                }

            }

            @Override
            public void onError(Throwable throwable, boolean b) {
                lsn.onComplete(false, null, ErrorCode.STATUS_IO_EXCEPTION, throwable.toString());

            }

            @Override
            public void onCancelled(CancelledException e) {

            }

            @Override
            public void onFinished() {

            }
        });
    }

    //公司统计
    public void GetXmAnalysis(final int type,String request,final OnResponseListener<List<PrjTj>> lsn){

        String token = (String) SharedPreferencesUtil.getData(mContext,"token","");

        String url = String.format("", token);
        RequestParams params = new RequestParams(Urls.GetAnalysisForCompanyByRiskType);
        params.setBodyContent(request);
        params.addHeader("UserToken", token);
        x.http().post(params, new Callback.CommonCallback<String>() {


            @Override
            public void onSuccess(String s) {

                try {


                    DbManager dbManager = DBUtil.getInstance(mContext).getDBManager();

                    LogUtils.getInstance().error("项目=======" + s);

                    JSONObject obj = new JSONObject(s);
                    JSONArray array = obj.getJSONArray("DataList");
                    List<PrjTj> prjList = new ArrayList<PrjTj>();
                    for (int i = 0; i < array.length(); i++) {

                        PrjTj prj = new PrjTj();
                        JSONObject data = array.getJSONObject(i);
                        int RiskType = -1;
                        int InspectType = -1;
                        int RiskLevel = -1;
                        String name = "";
                        if (type == 0) {
                            RiskType = data.getInt("RiskType");
                            Dic riskDic = dbManager.selector(Dic.class).where("dic_value", "=", RiskType + "").and("dic_type", "=", Constants.RiskType).findFirst();
                            if (riskDic != null) {
                                String riskTypeName = riskDic.getName();
                                prj.setRiskTypeName(riskTypeName);
                                name = riskTypeName;

                                LogUtils.getInstance().error(riskTypeName);
                            }
                            prj.setRiskType(RiskType);
                        } else if (type == 1) {

                            InspectType = data.getInt("InspectType");
                            Dic InspectTypeDic = dbManager.selector(Dic.class).where("dic_value", "=", InspectType + "").and("dic_type", "=", Constants.InspectType).findFirst();
                            if (InspectTypeDic != null) {
                                prj.setInspectTypeName(InspectTypeDic.getName());
                                name = InspectTypeDic.getName();

                            }
                            prj.setInspectType(InspectType);

                        } else if (type == 2) {
                            RiskLevel = data.getInt("RiskLevel");
                            Dic RiskLevelDic = dbManager.selector(Dic.class).where("dic_value", "=", RiskLevel + "").and("dic_type", "=", Constants.RiskLevel).findFirst();
                            if (RiskLevelDic != null) {
                                prj.setRiskLevelName(RiskLevelDic.getName());
                                name = RiskLevelDic.getName();

                            }
                            prj.setRiskLevel(RiskLevel);
                        } else if (type == 3) {
                            name = data.getString("ItemName");

                            prj.setItemName(data.getString("ItemName"));
                        }


                        JSONArray prjArray = data.getJSONArray("ProjectList");
                        List<PrjTjDetail> details = new ArrayList<PrjTjDetail>();
                        int totalCount = 0;
                        for (int j = 0; j < prjArray.length(); j++) {

                            JSONObject orgObj = prjArray.getJSONObject(j);
                            String ProjectCode = orgObj.getString("ProjectCode");
                            int AnalysisCount = orgObj.getInt("AnalysisCount");
//                            if(AnalysisCount == 0){
//                                AnalysisCount = new Random().nextInt(100);
//
//                            }
                            String ProjectName = orgObj.getString("ProjectName");
                            PrjTjDetail detail = new PrjTjDetail();
                            detail.setProjectCode(ProjectCode);
                            detail.setProjectName(ProjectName);
                            detail.setAnalysisCount(AnalysisCount);
                            details.add(detail);

                            totalCount += AnalysisCount;
                        }


                        prj.setName(name);
                        prj.setTotalCount(totalCount);
                        prj.setList(details);
                        prjList.add(prj);

                    }


                    lsn.onComplete(true, prjList, ErrorCode.STATUS_OK, "失败");


                } catch (Exception e) {
                    LogUtils.getInstance().error(e.toString());
                    lsn.onComplete(false, null, ErrorCode.STATUS_FAIL, "失败");
                }

            }

            @Override
            public void onError(Throwable throwable, boolean b) {
                lsn.onComplete(false, null, ErrorCode.STATUS_IO_EXCEPTION, throwable.toString());

            }

            @Override
            public void onCancelled(CancelledException e) {

            }

            @Override
            public void onFinished() {

            }
        });
    }


    //根据检查项 ID 获取详情信息
    public void GetInspectItemDetail(final String zyName,final String zyCode,String id,final OnResponseListener<InspectItem> lsn){

        String token = (String) SharedPreferencesUtil.getData(mContext,"token","");

        final DbManager dbManager = DBUtil.getInstance(mContext).getDBManager();
        String url = String.format(Urls.GetInspectItemDetail, id);
        RequestParams params = new RequestParams(url);
        params.addHeader("UserToken", token);
        LogUtils.getInstance().error("检查项详情=====" + url);
        x.http().get(params, new Callback.CommonCallback<String>() {


            @Override
            public void onSuccess(String s) {

                try {

                    LogUtils.getInstance().error(s);
                    InspectItem item = new InspectItem();

                    JSONObject data = new JSONObject(s);
                    int InspectItemID = data.getInt("InspectItemID");
                    String InspectItemName = data.getString("InspectItemName");
                    String InspectItemCode = data.getString("InspectItemCode");
                    int InspectType = data.getInt("InspectType");
                    int RiskType = data.getInt("RiskType");
                    Dic riskDic = dbManager.selector(Dic.class).where("dic_value", "=", RiskType + "").and("dic_type", "=", Constants.RiskType).findFirst();
                    if (riskDic != null) {
                        item.setRiskName(riskDic.getName());
                    }

                    item.setInspectItemID(InspectItemID);
                    item.setInspectItemName(InspectItemName);
                    item.setInspectItemCode(InspectItemCode);
                    item.setSpecialtyCode(zyCode);
                    item.setZyName(zyName);
                    item.setInspectType(InspectType);
                    item.setRiskType(RiskType);

                    List<InspectContent> contentsList = new ArrayList<InspectContent>();
                    JSONArray contentArray = data.getJSONArray("InspectContentList");
                    for (int j = 0; j < contentArray.length(); j++) {

                        JSONObject contentObj = contentArray.getJSONObject(j);
                        int InspectContentID = contentObj.getInt("InspectContentID");
                        String InspectContentName = contentObj.getString("InspectContentName");
                        int MaxPoints = contentObj.getInt("MaxPoints");

                        InspectContent content = new InspectContent();
                        content.setInspectItemID(InspectItemID);
                        content.setInspectContentID(InspectContentID + "");
                        content.setInspectContentName(InspectContentName);
                        content.setMaxPoints(MaxPoints);
                        contentsList.add(content);

                    }

                    DBUtil.getInstance(mContext).getDBManager().saveOrUpdate(contentsList);
                    item.setList(contentsList);
                    DBUtil.getInstance(mContext).getDBManager().saveOrUpdate(item);
                    lsn.onComplete(true, item, ErrorCode.STATUS_OK, "失败");

                } catch (Exception e) {
                    LogUtils.getInstance().error("===pars===="+e.toString());
                    lsn.onComplete(false, null, ErrorCode.STATUS_FAIL, "失败");
                }

            }

            @Override
            public void onError(Throwable throwable, boolean b) {
                lsn.onComplete(false, null, ErrorCode.STATUS_IO_EXCEPTION, throwable.toString());

            }

            @Override
            public void onCancelled(CancelledException e) {

            }

            @Override
            public void onFinished() {

            }
        });
    }


    //获取待审核明细

    public void GetPenddingAuditRepairRecordDetail(String InspectionID,String InspectionItemID, final OnResponseListener<DzgDetail> lsn){

        String token = (String) SharedPreferencesUtil.getData(mContext,"token","");

        String url = String.format(Urls.GetPenddingAuditRepairRecordDetail, InspectionID,InspectionItemID);
        LogUtils.getInstance().error("url===" + url);
        RequestParams params = new RequestParams(url);
        params.addHeader("UserToken", token);
        x.http().get(params, new Callback.CommonCallback<String>() {


            @Override
            public void onSuccess(String s) {

                try {

                    LogUtils.getInstance().error("待整改详情=====" + s);

                    JSONObject obj = new JSONObject(s);
                    boolean success = obj.getBoolean("Success");
                    if (success) {
                        DzgDetail detail = new DzgDetail();
                        // int RiskID = obj.getInt("RiskID");
                        int InspectionID = obj.getInt("InspectionID");
                        int InspectItemID = obj.getInt("InspectItemID");
                        String InspectProfessionName = obj.getString("InspectProfessionName");
                        String InspectItemName = obj.getString("InspectItemName");
                        String InspectTaskName = obj.getString("InspectTaskName");
                        String InspectType = obj.getString("InspectType");
                      //  int RiskType = obj.getInt("RiskType");
                        String InspectOrgCode = obj.getString("InspectOrgCode");
                        String InspectOrgName = obj.getString("InspectOrgName");
                        int InspectCompanyID = obj.getInt("InspectCompanyID");
                        String InspectProjectDPTID = obj.getString("InspectProjectDPTID");
                        int InspectProjectID = obj.getInt("InspectProjectID");
                        String InspectProjectDPTName = obj.getString("InspectProjectDPTName");
                        String InspectProjectName = obj.getString("InspectProjectName");
                        String DeadLine = obj.getString("DeadLine");
                        // detail.setRiskID(RiskID);
                        detail.setInspectionID(InspectionID);
                        detail.setInspectItemID(InspectItemID);
                        detail.setInspectProfessionName(InspectProfessionName);
                        detail.setInspectItemName(InspectItemName);
                        detail.setInspectTaskName(InspectTaskName);
                        detail.setInspectType(InspectType);
                        //detail.setRiskType(RiskType);
                        detail.setInspectOrgCode(InspectOrgCode);
                        detail.setInspectOrgName(InspectOrgName);
                        detail.setInspectCompanyID(InspectCompanyID);
                        detail.setInspectProjectDPTID(InspectProjectDPTID);
                        detail.setInspectProjectID(InspectProjectID);
                        detail.setInspectProjectDPTName(InspectProjectDPTName);
                        detail.setInspectProjectName(InspectProjectName);
                        detail.setDeadLine(DeadLine);

                        JSONArray array = obj.getJSONArray("InspectTaskList");
                        List<DzgInspectTask> dzgs = new ArrayList<DzgInspectTask>();
                        for (int i = 0; i < array.length(); i++) {

                            DzgInspectTask task = new DzgInspectTask();
                            JSONObject data = array.getJSONObject(i);
                            int InspectTaskID = data.getInt("InspectTaskID");
                            int Points = data.getInt("Points");
                            String InspectContentDesc = data.getString("InspectContentDesc");
                            String InspectRiskDesc = data.getString("InspectRiskDesc");
                            String InspectContentStatus = data.getString("InspectContentStatus");
                            String InspectContentAuditStatus = data.getString("InspectContentAuditStatus");
                            String RiskTypeName = data.getString("RiskTypeName");
                            int RiskType = data.getInt("RiskType");
                            task.setInspectTaskID(InspectTaskID);
                            task.setPoints(Points);
                            task.setInspectContentDesc(InspectContentDesc);
                            task.setInspectRiskDesc(InspectRiskDesc);
                            task.setInspectContentStatus(InspectContentStatus);
                            task.setInspectContentAuditStatus(InspectContentAuditStatus);
                            task.setRiskType(RiskType);
                            task.setRiskTypeName(RiskTypeName);

                            JSONArray imgArray = data.getJSONArray("RiskAttshUrlList");
                            List<String> imgs = new ArrayList<String>();
                            for (int j = 0; j < imgArray.length(); j++) {
                                String img = imgArray.getString(j);
                                imgs.add(img);
                            }
                            task.setImgList(imgs);
                            dzgs.add(task);
                        }

                        detail.setTaskList(dzgs);
                        lsn.onComplete(true, detail, ErrorCode.STATUS_OK, "失败");

                    } else {
                        lsn.onComplete(false, null, ErrorCode.STATUS_FAIL, "失败");

                    }


                } catch (Exception e) {
                    LogUtils.getInstance().error(e.toString());
                    lsn.onComplete(false, null, ErrorCode.STATUS_FAIL, "失败");
                }

            }

            @Override
            public void onError(Throwable throwable, boolean b) {
                LogUtils.getInstance().error(throwable.toString());

                lsn.onComplete(false, null, ErrorCode.STATUS_IO_EXCEPTION, throwable.toString());

            }

            @Override
            public void onCancelled(CancelledException e) {

            }

            @Override
            public void onFinished() {

            }
        });
    }

    //============质量监控===============
    public void GetCriticalActivity(final String projectId,final String keyword,final String SGStatus,final String Status,final String PageIndex,final String PageSize,final OnResponseListener<List<Gjgx>> lsn){

        String token = (String) SharedPreferencesUtil.getData(mContext,"token","");
        String uid = (String) SharedPreferencesUtil.getData(mContext,"uid","");

        String url = String.format(Urls.GetCriticalActivity,uid,projectId,keyword,SGStatus,Status);
        LogUtils.getInstance().error("关键工序列表  url======" + url);
        RequestParams params = new RequestParams(url);
        params.addHeader("UserToken", token);
        x.http().get(params, new Callback.CommonCallback<String>() {


            @Override
            public void onSuccess(String s) {

                try {
                    LogUtils.getInstance().error("关键工序列表" + s);
                    JSONObject obj = new JSONObject(s);
                    List<Gjgx> list = new ArrayList<Gjgx>();
                    boolean Success = obj.getBoolean("Success");
                    if (Success) {


                        int PageIndex = obj.getInt("PageIndex");
                        int PageSize = obj.getInt("PageSize");
                        JSONArray array = obj.getJSONArray("Items");
                        for (int i = 0; i < array.length(); i++) {
                            JSONObject data = array.getJSONObject(i);
                            int id = data.getInt("ID");
                            String Name = data.getString("Name");
                            String UnitProject = data.getString("UnitProject");
                            String PartProject = data.getString("PartProject");
                            String StartDate = data.getString("StartDate");
                            String SpecialProject = data.getString("SpecialProject");
                            String AttachList = data.getString("AttachList");
                            String FinishedDate = data.getString("FinishedDate");
                            String SPRemark = data.getString("SPRemark");

                            int Status = data.getInt("Status");
                            String UnitName = data.getString("UnitName");
                            String DeptName = data.getString("DeptName");
                            String ProjectName = data.getString("ProjectName");
                            int ManagerCheckStatus = data.getInt("ManagerCheckStatus");

                            Gjgx gjgx = new Gjgx();
                            gjgx.setID(id);
                            gjgx.setManagerCheckStatus(ManagerCheckStatus);
                            gjgx.setSPRemark(SPRemark);
                            gjgx.setName(Name);
                            gjgx.setStatus(Status);
                            gjgx.setUnitProject(UnitProject);
                            gjgx.setPartProject(PartProject);
                            gjgx.setStartDate(StartDate);
                            gjgx.setSpecialProject(SpecialProject);
                            gjgx.setFinishedDate(FinishedDate);
                            gjgx.setUnitName(UnitName);
                            gjgx.setDeptName(DeptName);
                            gjgx.setProjectName(ProjectName);


                            JSONArray attachArray = data.getJSONArray("AttachList");

                            List<String> attachUrl = new ArrayList<String>();
                            if (attachArray != null) {
                                for (int j = 0; j < attachArray.length(); j++) {

                                    attachUrl.add(attachArray.getString(j));

                                }
                            }

                            gjgx.setAttachUrl(attachUrl);
                            list.add(gjgx);


                        }

                    }
                    lsn.onComplete(true, list, ErrorCode.STATUS_OK, "成功");


                } catch (Exception e) {
                    LogUtils.getInstance().error(e.toString());
                    lsn.onComplete(false, null, ErrorCode.STATUS_FAIL, "失败");
                }

            }

            @Override
            public void onError(Throwable throwable, boolean b) {
                lsn.onComplete(false, null, ErrorCode.STATUS_IO_EXCEPTION, throwable.toString());

            }

            @Override
            public void onCancelled(CancelledException e) {

            }

            @Override
            public void onFinished() {

            }
        });
    }

    //待确认关键工序列表
    public void GetToBeConfirmedCriticalActivity(final String pageIndex,final String pageSize,final OnResponseListener<List<Gjgx>> lsn){

        String token = (String) SharedPreferencesUtil.getData(mContext,"token","");
        String uid = (String) SharedPreferencesUtil.getData(mContext,"uid","");

        String url = String.format(Urls.GetToBeConfirmedCriticalActivity, uid,pageIndex,pageSize);
        RequestParams params = new RequestParams(url);
        params.addHeader("UserToken", token);
        x.http().get(params, new Callback.CommonCallback<String>() {


            @Override
            public void onSuccess(String s) {

                try {


                    LogUtils.getInstance().error("待确认关键工序列表" + s);
                    JSONObject obj = new JSONObject(s);
                    List<Gjgx> list = new ArrayList<Gjgx>();

                    boolean Success = obj.getBoolean("Success");
                    if (Success) {


                        int PageIndex = obj.getInt("PageIndex");
                        int PageSize = obj.getInt("PageSize");
                        JSONArray array = obj.getJSONArray("Items");
                        for (int i = 0; i < array.length(); i++) {
                            JSONObject data = array.getJSONObject(i);
                            int id = data.getInt("ID");
                            String Name = data.getString("Name");
                            String UnitProject = data.getString("UnitProject");
                            String PartProject = data.getString("PartProject");
                            String StartDate = data.getString("StartDate");
                            String SpecialProject = data.getString("SpecialProject");
                            String AttachList = data.getString("AttachList");
                            String FinishedDate = data.getString("FinishedDate");
                            String SPRemark = data.getString("SPRemark");

                            int Status = data.getInt("Status");
                            String UnitName = data.getString("UnitName");
                            String DeptName = data.getString("DeptName");
                            String ProjectName = data.getString("ProjectName");

                            Gjgx gjgx = new Gjgx();
                            gjgx.setID(id);
                            gjgx.setSPRemark(SPRemark);
                            gjgx.setName(Name);
                            gjgx.setStatus(Status);
                            gjgx.setUnitProject(UnitProject);
                            gjgx.setPartProject(PartProject);
                            gjgx.setStartDate(StartDate);
                            gjgx.setSpecialProject(SpecialProject);
                            gjgx.setFinishedDate(FinishedDate);
                            gjgx.setUnitName(UnitName);
                            gjgx.setDeptName(DeptName);
                            gjgx.setProjectName(ProjectName);


                            JSONArray attachArray = data.getJSONArray("AttachList");

                            List<String> attachUrl = new ArrayList<String>();
                            if (attachArray != null) {
                                for (int j = 0; j < attachArray.length(); j++) {

                                    attachUrl.add(attachArray.getString(j));

                                }
                            }

                            gjgx.setAttachUrl(attachUrl);
                            list.add(gjgx);


                        }


                        lsn.onComplete(true, list, ErrorCode.STATUS_OK, "成功");
                    } else {

                    }


                } catch (Exception e) {
                    lsn.onComplete(false, null, ErrorCode.STATUS_FAIL, "失败");
                }

            }

            @Override
            public void onError(Throwable throwable, boolean b) {
                lsn.onComplete(false, null, ErrorCode.STATUS_IO_EXCEPTION, throwable.toString());

            }

            @Override
            public void onCancelled(CancelledException e) {

            }

            @Override
            public void onFinished() {

            }
        });
    }


    //实体情况采集列表

    public void GetEntityProjectList(final String ProjectId,final String Keyword,final String PageIndex, final OnResponseListener<List<Stcj>> lsn){

        String token = (String) SharedPreferencesUtil.getData(mContext,"token","");
        String uid = (String) SharedPreferencesUtil.getData(mContext,"uid","");

        String url = String.format(Urls.GetEntityProjectList, uid,ProjectId,Keyword,PageIndex);
        RequestParams params = new RequestParams(url);
        LogUtils.getInstance().error("实体情况采集列表 url====="+url);
        params.addHeader("UserToken", token);
        x.http().get(params, new Callback.CommonCallback<String>() {


            @Override
            public void onSuccess(String s) {

                try {
                    LogUtils.getInstance().error("实体情况采集===" + s);
                    JSONObject obj = new JSONObject(s);
                    boolean Success = obj.getBoolean("Success");
                    List<Stcj> list = new ArrayList<Stcj>();

                    if (Success) {

                        int PageIndex = obj.getInt("PageIndex");
                        int PageSize = obj.getInt("PageSize");
                        JSONArray array = obj.getJSONArray("Items");
                        for (int i = 0; i < array.length(); i++) {
                            JSONObject data = array.getJSONObject(i);
                            int id = data.getInt("InfoId");
                            String Name = data.getString("InfoName");
                            String InfoRemark = data.getString("InfoRemark");
                            String StartDate = data.getString("StartDate");
                            String UnitName = data.getString("UnitName");
                            String DeptName = data.getString("DeptName");
                            String FinishedDate = data.getString("FinishedDate");
                            String ProjectName = data.getString("ProjectName");

                            int Status = data.getInt("Status");
                            JSONArray attachArray = data.getJSONArray("AttachList");

                            List<String> attachUrl = new ArrayList<String>();
                            if (attachArray != null) {
                                for (int j = 0; j < attachArray.length(); j++) {
                                    attachUrl.add(attachArray.getString(j));
                                }
                            }
                            Stcj stcj = new Stcj();
                            stcj.setInfoName(Name);
                            stcj.setInfoRemark(InfoRemark);
                            stcj.setInfoId(id);
                            stcj.setUnitName(UnitName);
                            stcj.setStartDate(StartDate);
                            stcj.setFinishedDate(FinishedDate);
                            stcj.setDeptName(DeptName);
                            stcj.setProjectName(ProjectName);
                            stcj.setAttachList(attachUrl);
                            list.add(stcj);

                        }
                    }
                    lsn.onComplete(true, list, ErrorCode.STATUS_OK, "失败");

                } catch (Exception e) {
                    lsn.onComplete(false, null, ErrorCode.STATUS_FAIL, "失败");
                }

            }

            @Override
            public void onError(Throwable throwable, boolean b) {
                lsn.onComplete(false, null, ErrorCode.STATUS_IO_EXCEPTION, throwable.toString());

            }

            @Override
            public void onCancelled(CancelledException e) {

            }

            @Override
            public void onFinished() {

            }
        });
    }

    //提交确认工序完成

    public void Finished(final String request,final OnResponseListener<List<JcxDB>> lsn){

        String token = (String) SharedPreferencesUtil.getData(mContext,"token","");

        RequestParams params = new RequestParams(Urls.Finished);
        params.addHeader("UserToken", token);
        params.setBodyContent(request);
        x.http().post(params, new Callback.CommonCallback<String>() {


            @Override
            public void onSuccess(String s) {

                try {
                    LogUtils.getInstance().error("提交========" + s.toString());
                    JSONObject obj = new JSONObject(s);
                    boolean b = obj.getBoolean("Success");
                    if (b) {
                        lsn.onComplete(true, null, ErrorCode.STATUS_FAIL, "失败");
                    } else {
                        lsn.onComplete(false, null, ErrorCode.STATUS_FAIL, "失败");

                    }

                } catch (Exception e) {
                    LogUtils.getInstance().error(e.toString());
                    lsn.onComplete(false, null, ErrorCode.STATUS_FAIL, "失败");
                }

            }

            @Override
            public void onError(Throwable throwable, boolean b) {
                lsn.onComplete(false, null, ErrorCode.STATUS_IO_EXCEPTION, throwable.toString());

            }

            @Override
            public void onCancelled(CancelledException e) {

            }

            @Override
            public void onFinished() {

            }
        });
    }


    //确认工序

    public void Confirm(final String request,final OnResponseListener<List<JcxDB>> lsn){

        String token = (String) SharedPreferencesUtil.getData(mContext,"token","");

        RequestParams params = new RequestParams(Urls.Confirm);
        params.addHeader("UserToken", token);
        params.setBodyContent(request);
        x.http().post(params, new Callback.CommonCallback<String>() {


            @Override
            public void onSuccess(String s) {

                try {
                    LogUtils.getInstance().error("确认========" + s.toString());
                    JSONObject obj = new JSONObject(s);
                    boolean b = obj.getBoolean("Success");
                    if (b) {
                        lsn.onComplete(true, null, ErrorCode.STATUS_FAIL, "失败");
                    } else {
                        lsn.onComplete(false, null, ErrorCode.STATUS_FAIL, "失败");

                    }

                } catch (Exception e) {
                    LogUtils.getInstance().error(e.toString());
                    lsn.onComplete(false, null, ErrorCode.STATUS_FAIL, "失败");
                }

            }

            @Override
            public void onError(Throwable throwable, boolean b) {
                lsn.onComplete(false, null, ErrorCode.STATUS_IO_EXCEPTION, throwable.toString());

            }

            @Override
            public void onCancelled(CancelledException e) {

            }

            @Override
            public void onFinished() {

            }
        });
    }


    //实体上传

    public void SaveEntityProject(final String request,final OnResponseListener<List<JcxDB>> lsn){

        String token = (String) SharedPreferencesUtil.getData(mContext,"token","");

        RequestParams params = new RequestParams(Urls.SaveEntityProject);
        params.addHeader("UserToken", token);
        params.setBodyContent(request);
        x.http().post(params, new Callback.CommonCallback<String>() {


            @Override
            public void onSuccess(String s) {

                try {
                    LogUtils.getInstance().error("提交实体========" + s.toString());
                    JSONObject obj = new JSONObject(s);
                    boolean b = obj.getBoolean("Success");
                    if (b) {
                        lsn.onComplete(true, null, ErrorCode.STATUS_FAIL, "失败");
                    } else {
                        lsn.onComplete(false, null, ErrorCode.STATUS_FAIL, "失败");

                    }

                } catch (Exception e) {
                    LogUtils.getInstance().error(e.toString());
                    lsn.onComplete(false, null, ErrorCode.STATUS_FAIL, "失败");
                }

            }

            @Override
            public void onError(Throwable throwable, boolean b) {
                lsn.onComplete(false, null, ErrorCode.STATUS_IO_EXCEPTION, throwable.toString());

            }

            @Override
            public void onCancelled(CancelledException e) {

            }

            @Override
            public void onFinished() {

            }
        });
    }


    //实体上传

    public void GetPrivilege(final OnResponseListener<List<JcxDB>> lsn){

        String token = (String) SharedPreferencesUtil.getData(mContext,"token","");
        String uid = (String) SharedPreferencesUtil.getData(mContext,"uid","");

        String url = String.format(Urls.privilege,uid);
        LogUtils.getInstance().error("url====="+url);
        RequestParams params = new RequestParams(url);
        params.addHeader("UserToken", token);
        x.http().get(params, new Callback.CommonCallback<String>() {


            @Override
            public void onSuccess(String s) {

                try {
                    LogUtils.getInstance().error("权限========" + s.toString());
                    JSONObject obj = new JSONObject(s);
                    boolean b = obj.getBoolean("Success");
                    DBUtil.getInstance(mContext).getDBManager().delete(Privilege.class);
                    if (b) {
                        JSONArray array = obj.getJSONArray("Privileges");
                        List<Privilege> list = new ArrayList<Privilege>();
                        for(int i=0;i<array.length();i++){
                            String str =  array.getString(i);
                            Privilege p =new Privilege();
                            p.setName(str);
                            LogUtils.getInstance().error("========"+str);
                            p.setId(UUID.randomUUID().toString());
                            list.add(p);
                        }
//                        Privilege p =new Privilege();
//                        p.setName("ToBeConfirmedInspection");
//                        p.setId(UUID.randomUUID().toString());
//                        list.add(p);
                        DBUtil.getInstance(mContext).getDBManager().save(list);
                        lsn.onComplete(true, null, ErrorCode.STATUS_FAIL, "失败");
                    } else {
                        lsn.onComplete(false, null, ErrorCode.STATUS_FAIL, "失败");

                    }

                } catch (Exception e) {
                    LogUtils.getInstance().error(e.toString());
                    lsn.onComplete(false, null, ErrorCode.STATUS_FAIL, "失败");
                }

            }

            @Override
            public void onError(Throwable throwable, boolean b) {
                lsn.onComplete(false, null, ErrorCode.STATUS_IO_EXCEPTION, throwable.toString());

            }

            @Override
            public void onCancelled(CancelledException e) {

            }

            @Override
            public void onFinished() {

            }
        });
    }


    //获取部门
    public void QueryOrgsBm(final OnResponseListener<List<Org>> lsn){

        final String token = (String) SharedPreferencesUtil.getData(mContext,"token","");
        String uid = (String) SharedPreferencesUtil.getData(mContext,"uid","");

        String url = String.format(Urls.QueryOrgs, uid);
        RequestParams params = new RequestParams(url);
        params.addHeader("UserToken", token);
        LogUtils.getInstance().error("获取公司===" + url);

        x.http().get(params, new Callback.CommonCallback<String>() {


            @Override
            public void onSuccess(String s) {

                try {
                    LogUtils.getInstance().error("获取公司===" + s);
                    JSONObject obj = new JSONObject(s);
                    boolean success = obj.getBoolean("Success");
                    List<Org> orgs = new ArrayList<Org>();
                    List<Org> list = new ArrayList<Org>();
                    if (success) {

                        JSONArray array = obj.getJSONArray("OrgList");
                        for (int i = 0; i < array.length(); i++) {

                            JSONObject data = array.getJSONObject(i);
                            String OrgName = data.getString("OrgName");
                            String OrgCode = data.getString("OrgCode");
                            String OrgType = data.getString("OrgType");
                            String ParentOrgCode = data.getString("ParentOrgCode");
                            String ParentOrgName = data.getString("ParentOrgName");
                            String UnitCode = data.getString("UnitCode");
                            String UnitName = data.getString("UnitName");
                            String OrgGlobalNo = data.getString("OrgGlobalNo");
                            int OrgLevel = data.getInt("OrgLevel");
                            int OrgSequence = data.getInt("OrgSequence");

                            Org org = new Org();
                            org.setOrgName(OrgName);
                            org.setOrgCode(OrgCode);
                            org.setOrgType(OrgType);
                            org.setParentOrgCode(ParentOrgCode);
                            org.setParentOrgName(ParentOrgName);
                            org.setUnitCode(UnitCode);
                            org.setUnitName(UnitName);
                            org.setOrgGlobalNo(OrgGlobalNo);
                            org.setOrgLevel(OrgLevel);
                            org.setOrgSequence(OrgSequence);


                            orgs.add(org);

                            if (OrgLevel == 1) {
                                list.add(org);
                            }


                        }

                        lsn.onComplete(true, list, ErrorCode.STATUS_OK, "失败");

                    } else {
                        lsn.onComplete(false, null, ErrorCode.STATUS_FAIL, "失败");

                    }


                } catch (Exception e) {
                    LogUtils.getInstance().error(e.toString());
                    lsn.onComplete(false, null, ErrorCode.STATUS_FAIL, "失败");
                }

            }

            @Override
            public void onError(Throwable throwable, boolean b) {
                LogUtils.getInstance().error(throwable.toString());
                lsn.onComplete(false, null, ErrorCode.STATUS_IO_EXCEPTION, throwable.toString());

            }

            @Override
            public void onCancelled(CancelledException e) {

            }

            @Override
            public void onFinished() {

            }
        });
    }


    //获取所有的组织机构


    public void QueryAllOrgs(final OnResponseListener<List<Org>> lsn){

        final String token = (String) SharedPreferencesUtil.getData(mContext,"token","");
        String uid = (String) SharedPreferencesUtil.getData(mContext,"uid","");

        String url = String.format(Urls.GetAllOrgs, uid);
        RequestParams params = new RequestParams(url);
        params.addHeader("UserToken", token);
        LogUtils.getInstance().error("获取公司===" + url);

        x.http().get(params, new Callback.CommonCallback<String>() {


            @Override
            public void onSuccess(String s) {

                try {
                    LogUtils.getInstance().error("获取公司===" + s);
                    JSONObject obj = new JSONObject(s);
                    boolean success = obj.getBoolean("Success");
                    List<Org> orgs = new ArrayList<Org>();
                    List<Org> list = new ArrayList<Org>();
                    if (success) {

                        JSONArray array = obj.getJSONArray("OrgList");
                        for (int i = 0; i < array.length(); i++) {

                            JSONObject data = array.getJSONObject(i);
                            String OrgName = data.getString("OrgName");
                            String OrgCode = data.getString("OrgCode");
                            String OrgType = data.getString("OrgType");
                            String ParentOrgCode = data.getString("ParentOrgCode");
                            String ParentOrgName = data.getString("ParentOrgName");
                            String UnitCode = data.getString("UnitCode");
                            String UnitName = data.getString("UnitName");
                            String OrgGlobalNo = data.getString("OrgGlobalNo");
                            int OrgLevel = data.getInt("OrgLevel");
                            int OrgSequence = data.getInt("OrgSequence");

                            Org org = new Org();
                            org.setOrgName(OrgName);
                            org.setOrgCode(OrgCode);
                            org.setOrgType(OrgType);
                            org.setParentOrgCode(ParentOrgCode);
                            org.setParentOrgName(ParentOrgName);
                            org.setUnitCode(UnitCode);
                            org.setUnitName(UnitName);
                            org.setOrgGlobalNo(OrgGlobalNo);
                            org.setOrgLevel(OrgLevel);
                            org.setOrgSequence(OrgSequence);


                            orgs.add(org);
                            list.add(org);


                        }

                        lsn.onComplete(true, list, ErrorCode.STATUS_OK, "失败");

                    } else {
                        lsn.onComplete(false, null, ErrorCode.STATUS_FAIL, "失败");

                    }


                } catch (Exception e) {

                    LogUtils.getInstance().error(e.toString());
                    lsn.onComplete(false, null, ErrorCode.STATUS_FAIL, "失败");
                }

            }

            @Override
            public void onError(Throwable throwable, boolean b) {
                LogUtils.getInstance().error(throwable.toString());
                lsn.onComplete(false, null, ErrorCode.STATUS_IO_EXCEPTION, throwable.toString());

            }

            @Override
            public void onCancelled(CancelledException e) {

            }

            @Override
            public void onFinished() {

            }
        });
    }



    //确认陪同检查

    //待确认陪同
    public void GetAccompanyInspectionList(final OnResponseListener<List<DqrAccompany>> lsn){

        final String token = (String) SharedPreferencesUtil.getData(mContext,"token","");
        String uid = (String) SharedPreferencesUtil.getData(mContext,"uid","");

        String url = String.format(Urls.GetAccompanyInspectionList, uid);
        RequestParams params = new RequestParams(url);
        params.addHeader("UserToken", token);
        LogUtils.getInstance().error("获取公司===" + url);

        x.http().get(params, new Callback.CommonCallback<String>() {


            @Override
            public void onSuccess(String s) {


                LogUtils.getInstance().error("待确认陪同======"+s);

                try{
                    JSONObject obj = new JSONObject(s);
                    boolean isSuccess =  obj.getBoolean("Success");
                    List<DqrAccompany> list = new ArrayList<DqrAccompany>();
                    if(isSuccess){


                        JSONArray array = obj.getJSONArray("List");
                        for(int i=0;i<array.length();i++){
                            JSONObject data =  array.getJSONObject(i);
                            int AccompanyID = data.getInt("AccompanyID") ;
                            String UserID = data.getString("UserID");
                            int InspectionID = data.getInt("InspectionID");
                            String InspectionNo = data.getString("InspectionNo");
                            int IsAccompany = data.getInt("IsAccompany");
                            String OrgName = data.getString("OrgName");
                            String DeptName = data.getString("DeptName");
                            String ProjectName = data.getString("ProjectName");
                            String InspectType = data.getString("InspectType");
                            String InspectDate = data.getString("InspectDate");

                            DqrAccompany dqr = new DqrAccompany();
                            dqr.setUserID(UserID);
                            dqr.setAccompanyID(AccompanyID);
                            dqr.setInspectionID(InspectionID);
                            dqr.setDeptName(DeptName);
                            dqr.setInspectionNo(InspectionNo);
                            dqr.setProjectName(ProjectName);
                            dqr.setOrgName(OrgName);
                            dqr.setInspectDate(InspectDate);
                            dqr.setInspectName(InspectType);
                            list.add(dqr);
                        }
                        lsn.onComplete(true, list, ErrorCode.STATUS_OK, "失败");

                    }else{
                        lsn.onComplete(false, null, ErrorCode.STATUS_FAIL, "失败");

                    }


                }catch(Exception e){
                    lsn.onComplete(false, null, ErrorCode.STATUS_FAIL, "失败");

                }

            }

            @Override
            public void onError(Throwable throwable, boolean b) {
                LogUtils.getInstance().error(throwable.toString());
                lsn.onComplete(false, null, ErrorCode.STATUS_IO_EXCEPTION, throwable.toString());

            }

            @Override
            public void onCancelled(CancelledException e) {

            }

            @Override
            public void onFinished() {

            }
        });
    }


    //待确认陪同
    public void ConfirmAccompany(String id,final OnResponseListener<String> lsn){

        final String token = (String) SharedPreferencesUtil.getData(mContext,"token","");
        String url = String.format(Urls.ConfirmAccompany, id);
        RequestParams params = new RequestParams(url);


        LogUtils.getInstance().error("===url====" + url);
        params.addHeader("UserToken", token);

        x.http().get(params, new Callback.CommonCallback<String>() {

            @Override
            public void onSuccess(String s) {


                LogUtils.getInstance().error("确认陪同======" + s);

                try {
                    JSONObject obj = new JSONObject(s);
                    boolean isSuccess = obj.getBoolean("Success");
                    if (isSuccess) {
                        lsn.onComplete(true, "", ErrorCode.STATUS_OK, "失败");
                    } else {
                        lsn.onComplete(false, null, ErrorCode.STATUS_FAIL, "失败");

                    }


                } catch (Exception e) {
                    lsn.onComplete(false, null, ErrorCode.STATUS_FAIL, "失败");

                }

            }

            @Override
            public void onError(Throwable throwable, boolean b) {
                LogUtils.getInstance().error(throwable.toString());
                lsn.onComplete(false, null, ErrorCode.STATUS_IO_EXCEPTION, throwable.toString());

            }

            @Override
            public void onCancelled(CancelledException e) {

            }

            @Override
            public void onFinished() {

            }
        });
    }


    public void checkVersion(final OnResponseListener<AppVersion> lsn){

        final String token = (String) SharedPreferencesUtil.getData(mContext,"token","");
        String url = String.format(Urls.GetLatestVersion);
        RequestParams params = new RequestParams(url);


        LogUtils.getInstance().error("===url====" + url);
        params.addHeader("UserToken", token);

        x.http().get(params, new Callback.CommonCallback<String>() {

            @Override
            public void onSuccess(String s) {


                LogUtils.getInstance().error("====s====="+s);
                try {

                    JSONObject obj = new JSONObject(s);
                    boolean isSuccess = obj.getBoolean("Success");
                    if (isSuccess) {
                        int code = obj.getInt("Code");
                        String VersionNo = obj.getString("VersionNo");
                        String VersionDesc = obj.getString("VersionDesc");
                        String url = obj.getString("AppUrl");
                        AppVersion version = new AppVersion();
                        version.setCode(code);
                        version.setAppUrl(url);
                        version.setDesc(VersionDesc);
                        version.setVersionNo(VersionNo);
                        lsn.onComplete(true,version, ErrorCode.STATUS_OK, "失败");
                    } else {
                        lsn.onComplete(false, null, ErrorCode.STATUS_FAIL, "失败");

                    }


                } catch (Exception e) {
                    lsn.onComplete(false, null, ErrorCode.STATUS_FAIL, "失败");

                }

            }

            @Override
            public void onError(Throwable throwable, boolean b) {
                LogUtils.getInstance().error(throwable.toString());
                lsn.onComplete(false, null, ErrorCode.STATUS_IO_EXCEPTION, throwable.toString());

            }

            @Override
            public void onCancelled(CancelledException e) {

            }

            @Override
            public void onFinished() {

            }
        });
    }

}
